Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 760
Chris Avatar asked May 04 '15 19:05

Chris


1 Answers

I would put this in a comment, but I don't have enough reputation yet.

I've had this issue using ui-router before. The problem in my case was authorization logic inside of $rootScope.$on('$stateChangeStart'), which was kicking it into an infinite loop. What I did to figure out my issue was set breakpoints in Chrome on all of the areas of code in my module.run / config where it was redirecting with $state.go. I was able to step through the logic and see where the infinite loop started.

like image 93
DerekMT12 Avatar answered Oct 20 '22 18:10

DerekMT12