Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging $rootScope:infdig

Tags:

angularjs

This is a common problem:

5 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []

The documentation (https://docs.angularjs.org/error/$rootScope/infdig) explains what NOT to do to avoid the situation.

However, once in a while, you end up in the situation anyway. And for a project larger than a toy app, finding the cause of the infinite digest loop can be really hard.

I'm looking for debugging hints on how I can find out where the code is located which causes the loop.

like image 347
Markus Johansson Avatar asked Sep 24 '15 08:09

Markus Johansson


2 Answers

question was already answered here - How to Troubleshoot Angular "10 $digest() iterations reached" Error

as a resume of two best answers:

  1. remove all suspicious HTML - basically remove all your html from the template, and check if there are no warnings (https://stackoverflow.com/a/17129274/274500)
  2. usually it happens when function returns an new object (https://stackoverflow.com/a/17116322/274500)

plus

you can always put conditional breakpoint here https://github.com/angular/angular.js/blob/c3220325a0a95484724a03bedca24e1bbf05dc80/src/ng/rootScope.js#L815 to check the exception stacktrace.

like image 137
Stepan Suvorov Avatar answered Oct 23 '22 09:10

Stepan Suvorov


There can be multiple reasons to it. One of the common reason I've faced is due to a filter in the ng-repeat which returns a new array to work on the ng-repeat.

So check your ng-repeat expressions which have associated filters which is modifying the array.

like image 34
Shashank Agrawal Avatar answered Oct 23 '22 07:10

Shashank Agrawal