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

Commit 600a41a

Browse files
lgalfasorodyhaddad
authored andcommitted
fix($parse): Handle one-time to null
Handles when a one-time binding stabilizes to `null` Closes #7743 Closes #7787
1 parent 398053c commit 600a41a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ng/parse.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,8 @@ function $ParseProvider() {
10551055
if (oneTimeParseFn.$$unwatch && self && self.$$postDigestQueue) {
10561056
self.$$postDigestQueue.push(function () {
10571057
// create a copy if the value is defined and it is not a $sce value
1058-
if ((stable = isDefined(lastValue)) && !lastValue.$$unwrapTrustedValue) {
1058+
if ((stable = isDefined(lastValue)) &&
1059+
(lastValue === null || !lastValue.$$unwrapTrustedValue)) {
10591060
lastValue = copy(lastValue, null);
10601061
}
10611062
});

test/ng/parseSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,18 @@ describe('parser', function() {
10121012

10131013
value.baz = 'baz';
10141014
expect(fn()).toEqual({bar: 'bar'});
1015+
}));
10151016

1017+
it('should not throw if the stable value is `null`', inject(function($parse, $rootScope) {
1018+
var fn = $parse('::foo');
1019+
$rootScope.$watch(fn);
1020+
$rootScope.foo = null;
1021+
$rootScope.$digest();
1022+
$rootScope.foo = 'foo';
1023+
$rootScope.$digest();
1024+
expect(fn()).toEqual(null);
10161025
}));
1026+
10171027
});
10181028

10191029

0 commit comments

Comments
 (0)