如何解决 Angular “达到 10 $digest() 迭代"的问题错误 [英] How to Troubleshoot Angular "10 $digest() iterations reached" Error

查看:32
本文介绍了如何解决 Angular “达到 10 $digest() 迭代"的问题错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

达到 10 次 $digest() 迭代.正在中止!

10 $digest() iterations reached. Aborting!

Watchers 在最近 5 次迭代中被触发:"等意义上的支持文本有很多,但这些文本中有很多是来自各种功能的 Javascript 代码.是否有诊断此问题的经验法则?这是一个总是可以缓解的问题,还是有足够复杂的应用程序应该将此问题视为警告?

There is a lot of supporting text in the sense of "Watchers fired in the last 5 iterations: ", etc., but a lot of this text is Javascript code from various functions. Are there rules of thumb for diagnosing this problem? Is it a problem that can ALWAYS be mitigated, or are there applications complex enough that this issue should be treated as just a warning?

推荐答案

正如 Ven 所说,您要么在每个 $digest 循环中返回不同(不相同)的对象,要么正在更改数据太多次了.

as Ven said, you are either returning different (not identical) objects on each $digest cycle, or you are altering the data too many times.

找出应用的哪个部分导致此行为的最快解决方案是:

  1. 删除所有可疑的 HTML - 基本上从模板中删除所有的 html,并检查是否没有警告
  2. 如果没有警告 - 添加您删除的 html 的一小部分并检查问题是否再次出现
  3. 重复第 2 步,直到收到警告 - 您将找出 html 的哪一部分导致了问题
  4. 进一步调查 - 第 3 步的部分负责改变 $scope 上的对象,或者在每个 $digest 循环中返回不同的对象.
  5. 如果您在第 1 步之后仍然有 $digest 迭代警告,那么您可能正在做一些非常可疑的事情.对父模板/范围/控制器重复相同的步骤
  1. remove all suspicious HTML - basically remove all your html from the template, and check if there are no warnings
  2. if there are no warnings - add small parts of the html you removed and check if the problem is back
  3. repeat step 2 until you get a warning - you will figure out which part of your html is responsible for the problem
  4. investigate further - the part from step 3 is responsible for either mutating the objects on the $scope or is returning non-identical objects on each $digest cycle.
  5. if you still have $digest iteration warnings after step 1, than you are probably doing something very suspicious. Repeat the same steps for parent template/scope/controller

您还希望确保不会更改自定义过滤器的输入

请记住,在 JavaScript 中,有一些特定类型的对象的行为与您通常预期的不同:

Keep in mind, that in JavaScript there are specific types of objects that don't behave like you would normally expect:

new Boolean(true) === new Boolean(true) // false
new Date(0) == new Date(0) // false
new String('a') == new String('a') // false
new Number(1) == new Number(1) // false
[] == [] // false
new Array == new Array // false
({})==({}) // false

这篇关于如何解决 Angular “达到 10 $digest() 迭代"的问题错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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