aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSekib Omazic2014-02-09 17:58:11 +0100
committerTobias Bosch2014-03-21 13:05:29 -0700
commite48c28fe9292efe7af6205b2be116d2350990c73 (patch)
tree79dcbaee8d50bc86b30315d63823573b1bfabc14
parent10d3e1e4472ab9f5cf4418b6438ec2e0f2b0b288 (diff)
downloadangular.js-e48c28fe9292efe7af6205b2be116d2350990c73.tar.bz2
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
-rw-r--r--src/ng/rootScope.js4
-rw-r--r--test/ng/rootScopeSpec.js4
2 files changed, 7 insertions, 1 deletions
diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js
index ce0f8ad5..dbb93000 100644
--- a/src/ng/rootScope.js
+++ b/src/ng/rootScope.js
@@ -453,7 +453,9 @@ 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];
}
diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js
index 251a8ce8..2ea41489 100644
--- a/test/ng/rootScopeSpec.js
+++ b/test/ng/rootScopeSpec.js
@@ -603,6 +603,10 @@ describe('Scope', function() {
expect(log.empty()).toEqual([{newVal: [{}, []], oldVal: ['b', {}, []]}]);
});
+ it('should not infinitely digest when current value is NaN', function() {
+ $rootScope.obj = [NaN];
+ $rootScope.$digest();
+ });
it('should watch array-like objects like arrays', function () {
var arrayLikelog = [];