hyperN
hyperN

Reputation: 2754

Angularjs 10 $digest() iterations reached

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

Upvotes: 1

Views: 1451

Answers (1)

zs2020
zs2020

Reputation: 54543

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

Upvotes: 3

Related Questions