fix($parse): Handle one-time to null

Handles when a one-time binding stabilizes to `null`

Closes #7743
Closes #7787
This commit is contained in:
Lucas Galfaso
2014-06-11 16:11:48 +02:00
committed by rodyhaddad
parent 398053c563
commit 600a41a7b6
2 changed files with 13 additions and 2 deletions

View File

@@ -1055,7 +1055,8 @@ function $ParseProvider() {
if (oneTimeParseFn.$$unwatch && self && self.$$postDigestQueue) {
self.$$postDigestQueue.push(function () {
// create a copy if the value is defined and it is not a $sce value
if ((stable = isDefined(lastValue)) && !lastValue.$$unwrapTrustedValue) {
if ((stable = isDefined(lastValue)) &&
(lastValue === null || !lastValue.$$unwrapTrustedValue)) {
lastValue = copy(lastValue, null);
}
});

View File

@@ -1012,8 +1012,18 @@ describe('parser', function() {
value.baz = 'baz';
expect(fn()).toEqual({bar: 'bar'});
}));
it('should not throw if the stable value is `null`', inject(function($parse, $rootScope) {
var fn = $parse('::foo');
$rootScope.$watch(fn);
$rootScope.foo = null;
$rootScope.$digest();
$rootScope.foo = 'foo';
$rootScope.$digest();
expect(fn()).toEqual(null);
}));
});