0
之前,我有以下的(增加承诺的数组):Angularjs q.all射击承诺断定
function processInformation() {
var promisesArray = [];
for(var i =0; i<a.length; i++) {
var promise = this.getValue().then((response) => {
this.processValue(response).then(()=> {
// it gets here
});
});
promises.push(promise).
}
return $q.all(promises);
}
然后我打这个电话就像这样:
getInformation().then((response) =>{
// wait for the promises to be resolved
this.processInformation().then((r) => {
// never gets here
});
}).finally(()=> {
//gets here
});
这不是工作如预期的那样,因为它确实可以调用finally,并且它永远不会进入processInformation。我也尝试使用angular.forEach而不是for循环(在其他文章中建议),但它仍然无法正常工作。它确实进入processValue()的内部。什么是另一种方法来解决这个问题?
您的文章是矛盾的。你说它永远不会进入'processInformation'内部,并且它进入'processValue'内部,但是你发布的第一个函数是processInformation和processValue,这就是_inside_。你可以发布一个不会自相矛盾的实例吗?此外,我们不知道“this”,“a”或其他各种各样的东西是什么。这里有很多缺少的信息。最后,看起来你可能在调用'processInformation'时(假设)使用了错误的'this'。有没有你没有告诉我们的控制台错误? – JLRishe 2015-03-30 20:27:59