ng-repeat can't handle NaN values.
ng-repeat ends up in an infinite loop when "track by $index" is used and a NaN value appears in the collection.
Please see http://plnkr.co/edit/cV3mOq and uncomment the "breaking" line in script.js
@benol I'm not seeing the issue when I uncomment the offending line. It just gives me 5 and null.
The failure was more spectacular in my real code. Still, the plunker example fails with an error (if you check the JS console).
This looks like a $watchCollection problem, not ngRepeat: http://plnkr.co/edit/ci84Vz?p=preview
Encountered this same error. It was very hard to debug.
I think it keeps trying to check if NaN == NaN, and since it will never be true it reaches the TTL limit and throws an error.
Any suggestions for a work-around? Other than the obvious of not watching a collection containing NaN?
Throw a isNaN check on the value of the repeated index before you try to apply it in the template.
Sent from my iPhone
On Jan 20, 2014, at 6:34 PM, johndavidpearce [email protected] wrote:
Any suggestions for a work-around? Other than the obvious of not watching a collection containing NaN?
— Reply to this email directly or view it on GitHub.
Just saw your other that obvious ;). NaN is typeof number. You could handle the instance of the NaN with a filter to just display it in a friendly way if that is desired. Other than that you could put a directive on the loop that does a ng repeat with NaN checks.
Sent from my iPhone
On Jan 20, 2014, at 6:34 PM, johndavidpearce [email protected] wrote:
Any suggestions for a work-around? Other than the obvious of not watching a collection containing NaN?
— Reply to this email directly or view it on GitHub.
Thanks @breck421 , both of those are good suggestions. Now the only thing to do is remember this bug every time I see a "infinite digest" error and I'll be right!
isNaN() is broken.
You could polyfill Number.isNaN(), which works as expected, with something like Number.isNaN = function(val){ return val !== val; };
+1
@btford I assigned this to myself since I'm reviewing a PR that fixes the issue: #6192
thanks @jeffbcross