达到10次"digest()"迭代.正在中止!由于使用angularjs进行过滤 [英] "10 $digest() iterations reached. Aborting!" due to filter using angularjs

查看:39
本文介绍了达到10次"digest()"迭代.正在中止!由于使用angularjs进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看以下内容:

https://dl.dropbox.com/u/4571/musicopeTypescript/musicopeTypescript/index.html

在输入框中键入"a"时,将获得 10个$ digest()迭代次数.正在中止!错误.

when you type "a" in the input box, you obtain the 10 $digest() iterations reached. Aborting! error.

您有什么想法,为什么会这样?

Do you have any idea, why that happens?

编辑:这是引起问题的代码:

Here is the code that makes problems:

http://embed.plnkr.co/PTkvPc

编辑:看来这是Song.clone的问题.如果我用angular.copy替换它,那么它将起作用.有人可以解释吗?

It looks like it is a problem of Song.clone. If I replace it by angular.copy, then it works. Anybody could explain that?

这是工作版本:

http://plnkr.co/edit/8Jk1pR?p=preview

推荐答案

您的过滤器是否以某种方式修改了原始数据?这是唯一看起来会引起无限摘要循环的特定事物.

Is your filter modifying the original data somehow? That's the only specific thing that looks like it would cause the infinite digest cycle.

编辑:关于不同的克隆功能导致不同的行为.

EDIT: in regards to different cloning functions lead to different behavior.

我怀疑其中一个正在进行深度克隆,而另一个则没有,并且在某种情况下AngularJS正在检查对象是否相等,而您的过滤器每次都在创建新对象,从而导致问题.

I suspect one is doing deep cloning, the other is not, and in one case AngularJS is checking object equality and your filter is creating new objects each time, causing the problem.

我建议分解一些逻辑,也许将其中一些移入控制器或其他过滤器中.缩小数组范围的过滤器只能这样做,并且只返回对原始对象的引用.然后,您可以编写其他过滤器来操作标签等.

I'd suggest breaking up some of that logic and perhaps moving some of it into the controller or additional filters. The filter that narrows down your array should only be doing that, and just return references to the original objects. Then you can write other filters to manipulate the tags, etc.

对于Abba也+1.:P

Also +1 for Abba. :P

这篇关于达到10次"digest()"迭代.正在中止!由于使用angularjs进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆