How do I debug infdig with empty array in single page angular app?

时间:2015-05-04 19:47:35

标签: angularjs

I have a single page app that I have been working on with several coworkers for over a year. It's an angular app that uses angular-ui-router to move between pages. Sometimes, when visiting the settings page for the first time, the following exception is thrown:

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)

I understand [$rootScope:infdig] in the normal case, but the fact that the watchers array is empty is very confusing to me. Additionally, it has been very difficult to debug, because it only happens occasionally. Using the inspector, I was able to determine that the request that is completing is the loading of the settings HTML file. Removing various controllers from the settings page does not alleviate the issue, it seems to happen even when loading a dumb "shell" version of the settings page with only common widgets loaded.

How can I go about figuring out what's causing this empty infdig exception? How can I prevent it?

1 个答案:

答案 0 :(得分:1)

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

我之前使用ui-router有过这个问题。在我的案例中的问题是$rootScope.$on('$stateChangeStart')内部的授权逻辑,它将其踢入无限循环。我弄清楚我的问题是在我的module.run / config中使用$state.go重定向的所有代码区域中设置Chrome的断点。我能够逐步完成逻辑,看看无限循环的开始位置。