解决与角UI路由器的承诺阵列 [英] Resolve a promise array with Angular UI Router
本文介绍了解决与角UI路由器的承诺阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解决一个承诺阵列的事情
打我的控制器之前:
I'm trying to resolve a promise array to things
before hitting my controller:
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;
});
}
},
我在做什么错在这里?
What am I doing wrong here?
推荐答案
我想你需要:
return $q.all(promises).then(function(){
return titles;
});
由于没有这种外部回报内部收益不会去任何地方。
Because without that outer return the inner return doesn't go anywhere.
现在 resolve.things
返回一个承诺,那个时候解决,将包含标题的数组。
Now resolve.things
returns a promise, that when resolved, will contain an Array of titles.
与其他一些调整:
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);
}
}
这篇关于解决与角UI路由器的承诺阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文