gpt4 book ai didi

angularjs - 如何在单页 Angular 应用程序中使用空数组调试 infdig?

转载 作者:行者123 更新时间:2023-12-02 08:03:17 26 4
gpt4 key购买 nike

我有一个单页应用程序,我已经与几位同事一起开发了一年多。这是一个 Angular 应用程序,使用 Angular-ui-router 在页面之间移动。有时,第一次访问设置页面时,会抛出以下异常:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.3/$rootScope/infdig?p0=10&p1=%5B%5D
at REGEX_STRING_REGEXP (angular.js:63)
at Scope.$get.Scope.$digest (angular.js:14084)
at Scope.$get.Scope.$apply (angular.js:14308)
at done (angular.js:9532)
at completeRequest (angular.js:9717)
at XMLHttpRequest.requestLoaded (angular.js:9660)

在正常情况下我理解 [$rootScope:infdig],但 watchers 数组为空的事实让我感到非常困惑。此外,调试起来非常困难,因为这种情况只是偶尔发生。使用检查器,我能够确定正在完成的请求是加载设置 HTML 文件。从设置页面中删除各种 Controller 并不能缓解问题,即使加载仅加载常见小部件的设置页面的愚蠢“shell”版本,似乎也会发生这种情况。

我怎样才能找出导致这个空 infdig 异常的原因?我该如何预防?

最佳答案

我会把它放在评论中,但我还没有足够的声誉。

我之前使用 ui-router 时也遇到过这个问题。我的例子中的问题是 $rootScope.$on('$stateChangeStart') 内部的授权逻辑,这将其陷入无限循环。为了解决我的问题,我在 Chrome 中在 module.run/config 中使用 $state.go 重定向的所有代码区域中设置了断点。我能够单步执行逻辑并查看无限循环从哪里开始。

关于angularjs - 如何在单页 Angular 应用程序中使用空数组调试 infdig?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30038723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com