angularjs – 最大化$digest迭代
发布时间:2020-12-17 09:29:18 所属栏目:安全 来源:网络整理
导读:我正在玩这个 fiddle中的指令和绑定.我收到以下错误: Uncaught Error: 10 $digest() iterations reached. Aborting!Watchers fired in the last 5 iterations: [["fn: function () {n var parentValue = parentGet(parentScope);nn if (parentValue !==
我正在玩这个
fiddle中的指令和绑定.我收到以下错误:
Uncaught Error: 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [["fn: function () {n var parentValue = parentGet(parentScope);nn if (parentValue !== scope[scopeName]) {n // we are out of sync and need to copyn if (parentValue !== lastValue) {n // parent changed and it has precedencen lastValue = scope[scopeName] = parentValue;n } else {n // if the parent can be assigned then do son parentSet(parentScope,lastValue = scope[scopeName]);n }n }n return parentValue;n }; newVal: {"baz":3}; oldVal: {"baz":3}"],["fn: function () {n var parentValue = parentGet(parentScope);nn if (parentValue !== scope[scopeName]) {n // we are out of sync and need to copyn if (parentValue !== lastValue) {n // parent changed and it has precedencen lastValue = scope[scopeName] = parentValue;n } else {n // if the parent can be assigned then do son parentSet(parentScope,lastValue = scope[scopeName]);n }n }n return parentValue;n }; newVal: {"baz":3}; oldVal: {"baz":3}"]] angular.js:7729 Scope.$digest angular.js:7729 Scope.$apply angular.js:7894 (anonymous function) angular.js:930 invoke angular.js:2788 bootstrap angular.js:928 angularInit angular.js:904 (anonymous function) angular.js:14397 trigger angular.js:1695 (anonymous function) angular.js:1930 forEach angular.js:110 eventHandler angular.js:1929 为什么会发生这种情况?我认为它与=绑定有关.
这是因为它是在每次通过摘要循环时创建一个全新的对象.手表注册在这个=数据绑定中,因此每次评估bar =“{baz:3}”时,都会创建一个新对象,因此它将与先前的值不同,并且会导致另一个摘要循环.最终它会中止,使它不会无限循环.见
http://docs.angularjs.org/guide/concepts#runtime更全面的解释.
诀窍是使用不会随时更改的引用来执行= databing.这通常是通过将其放在指令之外的范围内完成的.见http://jsfiddle.net/u4BTu/7/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |