$ rootScope:因过滤器infdig错误? [英] $rootScope:infdig error caused by filter?
问题描述
我在NG-重复阵列上做一个过滤器。
I'm doing a filter on an array in an ng-repeat.
div.row(ng-repeat="log in logs | prepare_log | orderBy: 'log.created'")
在prepare_log过滤我做这样的:
In the prepare_log filter I'm doing this:
value.stack_trace = angular.fromJson(value.stack_trace)
如果我把它改成这样:
value.stack_trace = angular.fromJson(value.stack_trace).reverse()
我得到的infdig错误。
I get the infdig error.
我不知道这是否是相关的,但我遍历stack_trace财产在内部NG重复。
I don't know if it's relevant, but I'm iterating over the stack_trace property in an inner ng-repeat.
任何想法,我做错了什么吗?
Any ideas what I'm doing wrong here?
推荐答案
您正在造成一个无限$消化循环,因为你是在消化循环中改变模型。
You are causing an infinite $digest loop because you are changing the model during the digest loop.
会发生什么幕后是这样的:
What happens behind the scenes is this:
-
NG-重复解析收集前pression找出需要加盖什么行和实例得到通知的守望者,当收集的变化
ng-repeat parses the collection expression to figure out what rows need to be 'stamped' out and instantiates a watcher to get notified when the collection changes
每一个过滤器运行时,您可以通过分配一个新值 value.stack_trace
,引发了NG-重复的守望者更改的项目之一挑选这并开始一遍又一遍
every time the filter is run, you change one of the items by assigning a new value to value.stack_trace
, triggering the watcher of the ng-repeat to pick this up and starting over and over again
角检测回路并中止
要解决这个问题避免改变模型过滤器。
To solve the problem avoid changing the model in your filter.
希望帮助!
这篇关于$ rootScope:因过滤器infdig错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!