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

Commit 5038bf7

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 #8553 Closes #8554
1 parent e4e7e94 commit 5038bf7

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
@@ -1507,7 +1507,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15071507
if (parentGet.literal) {
15081508
compare = equals;
15091509
} else {
1510-
compare = function(a,b) { return a === b; };
1510+
compare = function(a,b) { return a === b || (a !== a && b !== b); };
15111511
}
15121512
parentSet = parentGet.assign || function() {
15131513
// 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
@@ -2869,6 +2869,28 @@ describe('$compile', function() {
28692869
});
28702870

28712871

2872+
it('should update parent scope when "="-bound NaN changes', inject(function($compile, $rootScope) {
2873+
$rootScope.num = NaN;
2874+
compile('<div my-component reference="num"></div>');
2875+
var isolateScope = element.isolateScope();
2876+
expect(isolateScope.reference).toBeNaN();
2877+
2878+
isolateScope.$apply(function(scope) { scope.reference = 64; });
2879+
expect($rootScope.num).toBe(64);
2880+
}));
2881+
2882+
2883+
it('should update isolate scope when "="-bound NaN changes', inject(function($compile, $rootScope) {
2884+
$rootScope.num = NaN;
2885+
compile('<div my-component reference="num"></div>');
2886+
var isolateScope = element.isolateScope();
2887+
expect(isolateScope.reference).toBeNaN();
2888+
2889+
$rootScope.$apply(function(scope) { scope.num = 64; });
2890+
expect(isolateScope.reference).toBe(64);
2891+
}));
2892+
2893+
28722894
describe('bind-once', function () {
28732895

28742896
function countWatches(scope) {

0 commit comments

Comments
 (0)