Angular js在调用$apply()时出现太多递归错误
angular js too much recursion error on $apply() call
每当我触发作用域上的$apply
时,都会抛出过多的递归错误。
:
Error: too much recursion
isArray@file://.../lib/angular.js:355:10
copy@file://.../lib/angular.js:551:9
copy@file://.../lib/angular.js:546:23
copy@file://.../lib/angular.js:563:28
...
Error: 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
$RootScopeProvider/this.$get</Scope.prototype.$digest@file://.../lib/angular.js:7756:19
$RootScopeProvider/this.$get</Scope.prototype.$apply@file://.../lib/angular.js:7926:13
递归错误太多
如果是由angularjs上的copy
方法引起的,你的数据之间有一个循环引用。
// you define your objects
var lot = new Lot();
var car = new Car();
// you assign create a relation to it
car.assign( lot );
lot.assign( car );
// lets assume that the data on the objects are like this
car; // {'lot':lot}
lot; // {'car':car}
当$apply()
被触发时,无论是你调用它还是角调用它,它都会在某处调用copy
方法。
发生在copy
的是复制每个属性和任何它可以复制的东西。当应用于我们上面的数据时,如果不停止,它将永远重复。
这会导致浏览器停止它并引发Too much recursion
错误。
解决方案:
只获取呈现元素所需的数据。只传递需要的数据。
使用上面的示例代码,
var reduced = {'plate':car.get_plate(),'lot':car.get_lot_location()};
my_scope.addCar( reduced );
提示self:在调试时使用未简化的库版本。:)
相关文章:
- 如何修复“;太多递归”;ReactJS中的错误
- Node.js错误:参数太多上传批量数据时出错
- 树中的递归错误太多
- "错误CS1012:字符文字“”中的字符太多;
- 由于发出太多 Axios 请求而导致的 ENFILE 错误
- 谷歌地图点击平移到新位置 递归错误太多
- 主干/下划线 js “太多递归”和“检查目标崩溃”错误
- Jquery 拆分器插件收到错误太多递归
- 内部错误:太多的递归 - 进入jquery
- 找不到错误 - 发射次数太多
- Gettin 交叉过滤器.js错误“太多递归”
- 避免'太多的递归'错误
- asp.net错误为“;文字字符“”中的字符太多;
- WebGL Fragment Shader构造函数错误-参数太多
- 节点和错误:EMFILE,打开的文件太多
- Babel 6:传递错误的参数太多
- Jquery加载函数,如果花费太多时间,会出现错误信息
- 太多的递归错误与facebook JavaScript SDK
- 错误:当使用(node -harmony debug.js)太多次时,听EADDRINUSE
- 我得到了错误:太多的递归.为什么呢?