Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template recursion limitation (digest loop) in angularjs

I use recursive templates to render a tree in angularJS, but when tree depth is above 10, AngularJS gives me an error on the console saying:

"Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

Example in this plnkr.

If I understand correctly and try to put simple words on it (I know it's more complex):

  • in the first $digest() iteration, it includes the first template and thus creates a ŵatcher over item (actually on item.ID and item.children
  • then instead of including the template recursively and create watchers afterwards, it first wants to check item.children, and reruns the digest loop with --ttl
  • then both values are the same, so it goes on and includes the next template and sets a watcher on the new item, and goes back to second step

Thus after 10 iterations, the ttl will be 0, hence the error, though there is no actual error...

So, a few questions:

  • is my analysis correct?
  • should I report this on the angular tracker (as I believe angular is wrong in reporting an error)?
  • is there a simple workaround?

Thank you very much!

Edit:

This plnkr (which you need to see with firefox because of a raw.github) shows that bindonce is not a solution to this...

like image 365
Elie Roux Avatar asked Feb 22 '14 18:02

Elie Roux


1 Answers

This is apparently a known issue of AngularJS, the only workarounds are not really satisfactory, See this issue.

like image 102
Elie Roux Avatar answered Sep 22 '22 13:09

Elie Roux