AngularJS v1.2.x $digest() 无限循环指令隔离范围对象参数
AngularJS v1.2.x $digest() infinite loop Directive isolated scope object param
问题的简化版本,查看 Web 开发控制台:http://plnkr.co/edit/3wKmWz?p=preview
Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations:
那么,为什么将对象传递到具有隔离作用域的指令中会导致无限$digest()循环呢?
// controller
// AngularJS 1.2.x infinite digest caused when returning object into directive
$scope.ctrlObjReturnFn = function() {
return {test:true};
}
// view
<div test-dir breaking-object="ctrlObjReturnFn()"></div
// directive
app.directive('testDir', function() {
return {
scope: { breakingObject: '=' },
link: function(scope, element, attrs) {
element.html('printed obj: ' + scope.breakingObject.toString());
}
}
});
这是因为您将函数作为 2 路绑定传递到指令中,这不是您应该做的,要么使用 2 路绑定传递对象:
scope: { breakingObject: '=' },
<div test-dir breaking-object="ctrlObjReturnFn"></div>
$scope.ctrlObjReturnFn = {test:true};
或使用 1 路绑定的函数:
scope: { breakingObject: '&' },
<div test-dir breaking-object="ctrlObjReturnFn()"></div>
$scope.ctrlObjReturnFn = function() {
return {test:true};
}
见扑通。
相关文章:
- 使用滚动溢出-x进行无限循环
- 从index.html调用函数,该函数无限循环
- 使用jQuery无限循环播放HTML页面幻灯片
- Grunt任务没有加载,获得无限循环
- 如何在不进入无限循环的情况下将网站重定向到Facebook画布URL
- Backbone+RequireJS+Mediator模式导致视图逻辑短路和无限循环
- jQuery无限循环,动画化许多项目
- 如何避免试图用php+jquery显示php起始页的无限循环
- 为什么ng中的自定义指令在循环完成后重复运行
- 6502仿真增强型基本无限循环$C000至$E0ED
- Angular ngRoute导致无限循环和堆栈溢出
- Jquery:无限循环和暂停
- 数组数组:无限循环
- MeteorJS使用流星调用和流星方法时的无限循环
- 如何无限循环数据集字符串
- jquery在无限循环中运行
- 遍历对象会导致无限循环
- 角度编译指令似乎进入了无限循环
- Angularjs 指令,函数双向绑定陷入无限循环
- AngularJS v1.2.x $digest() 无限循环指令隔离范围对象参数