Skip to content

Commit

Permalink
fix($rootScope): ng-repeat can't handle NaN values. angular#4605
Browse files Browse the repository at this point in the history
$watchCollection checks if oldValue !== newValue which does not work for NaN

Closes angular#4605
  • Loading branch information
sekib committed Feb 8, 2014
1 parent e645f7c commit 692b677
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ function $RootScopeProvider(){
}
// copy the items to oldValue and look for changes.
for (var i = 0; i < newLength; i++) {
if (oldValue[i] !== newValue[i]) {
var bothNaN = (oldValue[i] !== oldValue[i]) && (newValue[i] !== newValue[i]);
if (!bothNaN && (oldValue[i] !== newValue[i])) {
changeDetected++;
oldValue[i] = newValue[i];
}
Expand Down
7 changes: 7 additions & 0 deletions test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,13 @@ describe('Scope', function() {
log = [];
$rootScope.$digest();
expect(log).toEqual([ '[{},[]]' ]);

log = [];
$rootScope.obj[0] = NaN;
$rootScope.$digest();
expect(isNaN(log.shift())).toBe(true); //jasmine's toBe and toEqual don't work well with NaNs
//expect(log).toEqual([ ]);

});

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

0 comments on commit 692b677

Please sign in to comment.