【发布时间】:2017-04-29 15:45:53
【问题描述】:
我做了一个工厂,将我范围内的信息保存在一系列 6 页中。现在,当用户完成第 6 页并推送我希望工厂再次重置为空数组的对象时。
我已经尝试了很多超时和应用元素,还尝试了很多组合将数组设置为空(null、""、{})。但是当我再次加载页面时它仍然会加载旧信息(第 1/6 页)。
提交功能(也需要重置范围)是
$scope.send = function(){
if(ArrayInfo.Checkmark == true){
firebase.database().ref('lorem/' + ArrayInfo.Ordernumber).set({
info: ArrayInfo,
Dates: Dates,
gasmeter: gasmeter,
gasmeter1: gasmeter1
}).then(function(){
firebase.database().ref('lorem2/' + ArrayInfo.currentYear).set({
last_number: ArrayInfo.Ordervalue
});
}).then(function(){
//ArrayInfo = {};
setTimeout(function(){
ArrayInfo = "";
$scope.info = "";
$scope.$apply();
$scope.$digest();
}, 50);
});
//close newrental
setTimeout(function(){
if (window.confirm('Information saved! You are ready to leave this screen? no changes possible after this point'))
{
//disable back button in home
$ionicHistory.nextViewOptions({
disableBack: true
});
//go home
$state.go("app.auth");
}
//error close newrental
else
{
alert("Take your time");
}
}, 50);
}
//error send array
else {
alert("Please accept the terms and conditions.");
}
}
我的工厂是这样的
mainapp.factory("infoFactory", function(){
ArrayInfo = {};
placeholders = {
"licenseone" : "img/placeholder.png",
"licensetwo" : "img/placeholder.png",
"licensethree" : "img/placeholder.png",
"licensefour" : "img/placeholder.png",
"imageone" : "img/front.png",
"imagetwo" : "img/sideleft.png",
"imagethree" : "img/back.png",
"imagefour" : "img/sideright.png",
"imagefive" : "img/roof.png",
"imagesix" : "img/placeholder.png",
"imageseven" : "img/placeholder.png",
"imageeight" : "img/placeholder.png"
};
gasmeter = {
"url" : "img/gas/gas1.png",
"gasvalue" : "1"
}
gasmeter1 = {
"url" : "img/gas/gas1.png",
"gasvalue" : "1"
}
ArrayInfo.returned = false;
RawDate = {};
Dates = {};
console.log(ArrayInfo);
return ArrayInfo;
return gasmeter;
return gasmeter1;
return placeholders;
return RawDate;
return Dates;
})
然后我像这样在我的控制器中加载信息
$scope.info = infoFactory;
$scope.Dates = Dates;
$scope.RawDate = RawDate;
$scope.gasmeter = gasmeter;
$scope.gasmeter1 = gasmeter1;
我使用的角度版本是“3.6.6”
【问题讨论】:
-
没有“角度3.6.6”; Angularjs 是 1.6.4,Angular 是 4.1.0;完全跳过了 3.x 分支。
-
我的错,我将我的 angularfire 与我的 angular 版本混淆了。现在更新了。
-
我有多个数组,所以我认为我需要多个返回?还是我需要通过 infoFactory.Dates 来调用它们?
-
@AlonEitan 很好用!像这样设置时有什么方法可以轻松重置它?
标签: javascript angularjs arrays angularjs-scope angularjs-factory