Angularjs 10 $digest() iterations reached

给你一囗甜甜゛ 提交于 2020-01-05 07:54:10

问题


I have code like this:

$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");
                    }

                });

But I get error:

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 :)


回答1:


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); 


来源:https://stackoverflow.com/questions/18814449/angularjs-10-digest-iterations-reached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!