Skip to content

Commit 18113e5

Browse files
committed
fix($compile): make '='-bindings NaN-aware
Update parent and child scopes correctly when a '='-binding changes from a NaN value. TBR by angular-core Closes angular#8553 Closes angular#8554 Conflicts: test/ng/compileSpec.js
1 parent 18fc43e commit 18113e5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
14741474
if (parentGet.literal) {
14751475
compare = equals;
14761476
} else {
1477-
compare = function(a,b) { return a === b; };
1477+
compare = function(a,b) { return a === b || (a !== a && b !== b); };
14781478
}
14791479
parentSet = parentGet.assign || function() {
14801480
// reset the change, or we will throw this exception on every $digest

test/ng/compileSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -2671,6 +2671,28 @@ describe('$compile', function() {
26712671
});
26722672

26732673

2674+
it('should update parent scope when "="-bound NaN changes', inject(function($compile, $rootScope) {
2675+
$rootScope.num = NaN;
2676+
compile('<div my-component reference="num"></div>');
2677+
var isolateScope = element.isolateScope();
2678+
expect(isolateScope.reference).toBeNaN();
2679+
2680+
isolateScope.$apply(function(scope) { scope.reference = 64; });
2681+
expect($rootScope.num).toBe(64);
2682+
}));
2683+
2684+
2685+
it('should update isolate scope when "="-bound NaN changes', inject(function($compile, $rootScope) {
2686+
$rootScope.num = NaN;
2687+
compile('<div my-component reference="num"></div>');
2688+
var isolateScope = element.isolateScope();
2689+
expect(isolateScope.reference).toBeNaN();
2690+
2691+
$rootScope.$apply(function(scope) { scope.num = 64; });
2692+
expect(isolateScope.reference).toBe(64);
2693+
}));
2694+
2695+
26742696
describe('attribute', function() {
26752697
it('should copy simple attribute', inject(function() {
26762698
compile('<div><span my-component attr="some text">');

0 commit comments

Comments
 (0)