AngularJS $q.all update/notify 为什么没有调用? [英] AngularJS $q.all update/notify not called why?

查看:24
本文介绍了AngularJS $q.all update/notify 为什么没有调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个使用 $q.all 批处理 $resource 调用的简单示例,我想知道为什么我的更新处理程序从未被调用?

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?

我会认为它会在每个 promise 成功完成后被调用?

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?

这是代码片段:

      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 创建一个新的单一 promise,一旦所有先前的 promise 完成,就会继续执行.如果您想单独完成每一项,则必须单独引用它们.

$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 update/notify 为什么没有调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆