AngularJS $ q.all更新/通知不叫,为什么? [英] AngularJS $q.all update/notify not called why?
本文介绍了AngularJS $ q.all更新/通知不叫,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我必须使用$ q.all批量$资源调用一个简单的例子,我想知道的是为什么我更新处理从来不叫?
我还以为之后的每个承诺成功完成将它叫什么名字?
只有结果处理程序被调用。我在做什么错了?
下面是code片断:
VAR承诺= [];
angular.forEach($ scope.mappedData,功能(项目){
VAR资源=新的资源(项目);
promises.push(资源节约$());
}); $ q.all(承诺)。然后(
功能(结果){
的console.log(结果,结果); },
功能(错误){
的console.log('错误',错误); },
功能(通知){
的console.log(通知,通知);
}
);
解决方案
$ q.all创建一个新的奇异的承诺,一旦所有的previous承诺完成之后就会继续。如果你想独自做每一个你必须单独引用它们。
So I have a simple example of using $q.all to batch $resource calls, what I want to know is why is my update handler never called?
I would have thought it would be called after each promise is successfully completed?
Only the result handler is called. What am I doing wrong?
Here is the code snippet:
var promises = [];
angular.forEach($scope.mappedData, function(item) {
var resource = new Resource(item);
promises.push(resource.$save());
});
$q.all(promises).then(
function(result) {
console.log('result', result);
},
function(error) {
console.log('error', error);
},
function(notify) {
console.log('notify', notify);
}
);
解决方案
$q.all creates a new singular promise that once all the previous promises are complete will then continue on. If you want to do each one individually you'll have to reference them individually.
这篇关于AngularJS $ q.all更新/通知不叫,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文