问题
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