Skip to content

Commit f205c91

Browse files
committed
fix($rootScope): ng-repeat can't handle NaN values. angular#4605
$watchCollection checks if oldValue !== newValue which does not work for NaN Closes angular#4605
1 parent e645f7c commit f205c91

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/ng/rootScope.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ function $RootScopeProvider(){
448448
}
449449
// copy the items to oldValue and look for changes.
450450
for (var i = 0; i < newLength; i++) {
451-
if (oldValue[i] !== newValue[i]) {
451+
var bothNaN = (oldValue[i] !== oldValue[i]) && (newValue[i] !== newValue[i]);
452+
if (!bothNaN && (oldValue[i] !== newValue[i])) {
452453
changeDetected++;
453454
oldValue[i] = newValue[i];
454455
}

test/ng/rootScopeSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ describe('Scope', function() {
579579
log = [];
580580
$rootScope.$digest();
581581
expect(log).toEqual([ '[{},[]]' ]);
582+
583+
log = [];
584+
$rootScope.obj[0] = NaN;
585+
$rootScope.$digest();
586+
expect(isNaN(log.shift())).toBe(true); //jasmine's toBe and toEqual don't work well with NaNs
587+
//expect(log).toEqual([ ]);
588+
582589
});
583590

584591
it('should watch array-like objects like arrays', function () {

0 commit comments

Comments
 (0)