Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Error: $rootScope:infdig Infinite $digest Loop #16

Open
JulianWielga opened this issue Jul 9, 2014 · 2 comments
Open

Error: $rootScope:infdig Infinite $digest Loop #16

JulianWielga opened this issue Jul 9, 2014 · 2 comments

Comments

@JulianWielga
Copy link

copy-paste of your example:
http://plnkr.co/edit/Rr7WBeiwHbCSeQFZ7l19

@alexthewilde
Copy link

+1

@aolieman
Copy link

The cause is that Angular's digest loop evaluates expressions at least twice, to check if their output is stable. It clearly isn't in the case of shuffle, but other functions with non-deterministic return values, e.g. pairs(), will also cause Angular to get stuck.

The simple solution is to move any expressions with (intermediate, in the case of filters,) non-deterministic return values to your controller (i.e. out of the template). The workaround for this module that comes to mind is to sort the output of non-deterministic functions that are especially useful in templates (such as pairs()). It incurs a bit of overhead, and will be a less clean mapping to underscore, but it will make this module more usable. Currently, I end up shadowing sorted versions of these functions in my controllers.

It would be nice if Angular could take the entire expression into account (i.e. plus filters), so that this issue would not be caused by expressions that sort their output with filters. Perhaps someone would like to upstream this issue there.

EDIT: the workaround isn't as simple as I stated above. For users of this module, ngRepeat's track by clause may help. A true solution will likely involved modified $watch calls.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants