Angularjs 10 $digest() 迭代达到 [英] Angularjs 10 $digest() iterations reached

查看:32
本文介绍了Angularjs 10 $digest() 迭代达到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

$scope.flags = [];

$scope.$watch('selectedFilter', function() {    
            for (var i = 0; i < 2; i++) {
                $scope.flags.push(i);
            }    
    });

$scope.$watch('flags', function(oldval, newval) {

                    if (oldval != newval) {

                        console.log("hello");
                    }

                });

但我得到错误:

10 $digest() iterations reached. Aborting!

这是为什么?我怎样才能解决这个问题?请注意,这是我尝试做的事情的过度简化:)

Why is this ? And how can I come around this problem ? Note this is oversimplification of what I am trying to do :)

推荐答案

我想指出的一点是,当您观察列表的变化时,应该将第三个参数设置为 true.

One thing I want to point out is when you watch the change of a list, you should set the 3rd parameter to true.

$scope.$watch('flags', function (oldval, newval) {
    if (oldval != newval) {
        console.log("hello");
    }
}, true); 

这篇关于Angularjs 10 $digest() 迭代达到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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