[英]Resolve a promise array with Angular UI Router
我試圖解決一個承諾數組things
打我的控制器之前:
resolve:{
things: function($q){
var promises = [];
var titles = [];
var thingRef = ['a1', 'a2', 'a3'];
angular.forEach(thingRefs, function(thingRef){
promises.push($firebase(ref.child('things').child(thingRef).child('title')).then(function(title){
titles.push(title);
}));
});
$q.all(promises).then(function(){
return titles;
});
}
},
我在這做錯了什么?
我想你需要:
return $q.all(promises).then(function(){
return titles;
});
因為沒有那個外部回報,內部回報就不會到達任何地方。
現在resolve.things
返回一個promise,當解析時,它將包含一個標題數組。
進行一些其他調整:
resolve:{
things: function($q){
var promises = [];
var thingRef = ['a1', 'a2', 'a3'];
angular.forEach(thingRefs, function(thingRef){
promises.push($firebase(ref.child('things').child(thingRef).child('title')));
});
return $q.all(promises);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.