Angularjs 10 $摘要()达到迭代 [英] Angularjs 10 $digest() iterations reached
本文介绍了Angularjs 10 $摘要()达到迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有code是这样的:
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 :)
推荐答案
有一件事我想指出的是,当你看到一个列表的变化,你应该设置第三个参数为真实
。
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 $摘要()达到迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文