-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ng-repeat can't handle NaN values. #4605
Comments
@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 |
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
|
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
|
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 |
$watchCollection checks if oldValue !== newValue which does not work for NaN Closes angular#4605
$watchCollection checks if oldValue !== newValue which does not work for NaN Closes angular#4605
+1 |
thanks @jeffbcross |
* 'master' of https://github.com/angular/angular.js: fix($rootScope): ng-repeat can't handle NaN values. angular#4605 test(ngMock): workaround issue with negative timestamps fix(select): avoid checking option element selected properties in render fix(orderBy): support string predicates containing non-ident characters fix(ngCookie): convert non-string values to string fix(ngTouch): update workaround for desktop Webkit quirk fix($httpBackend): don't error when JSONP callback called with no parameter fix($$RAFProvider): check for webkitCancelRequestAnimationFrame docs(tutorial/step_05): fix services link docs(tutorial/step_05): removed stray "a" style(ngMocks): remove ws feat(ngMock.$httpBackend): added support for function as URL matcher feat($compile): add support for $observer deregistration fix(Scope): $watchCollection should call listener with oldValue chore(log): add `log.empty()` method to the testing logger
$watchCollection checks if oldValue !== newValue which does not work for NaN. This was causing infinite digest errors, since comparing NaN to NaN in $watchCollection would always return false, indicating that a change was occuring on each loop. This fix adds a simple check to see if the current value and previous value are both NaN, and if so, does not count it as a change. Closes #4605
$watchCollection checks if oldValue !== newValue which does not work for NaN. This was causing infinite digest errors, since comparing NaN to NaN in $watchCollection would always return false, indicating that a change was occuring on each loop. This fix adds a simple check to see if the current value and previous value are both NaN, and if so, does not count it as a change. Closes angular#4605
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
The text was updated successfully, but these errors were encountered: