Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e48c28f

Browse files
SekibOmazictbosch
authored andcommitted
fix($rootScope): ng-repeat can't handle NaN values. #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 #4605
1 parent 10d3e1e commit e48c28f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ng/rootScope.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ function $RootScopeProvider(){
453453
}
454454
// copy the items to oldValue and look for changes.
455455
for (var i = 0; i < newLength; i++) {
456-
if (oldValue[i] !== newValue[i]) {
456+
var bothNaN = (oldValue[i] !== oldValue[i]) &&
457+
(newValue[i] !== newValue[i]);
458+
if (!bothNaN && (oldValue[i] !== newValue[i])) {
457459
changeDetected++;
458460
oldValue[i] = newValue[i];
459461
}

test/ng/rootScopeSpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ describe('Scope', function() {
603603
expect(log.empty()).toEqual([{newVal: [{}, []], oldVal: ['b', {}, []]}]);
604604
});
605605

606+
it('should not infinitely digest when current value is NaN', function() {
607+
$rootScope.obj = [NaN];
608+
$rootScope.$digest();
609+
});
606610

607611
it('should watch array-like objects like arrays', function () {
608612
var arrayLikelog = [];

0 commit comments

Comments
 (0)