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

Commit 3a3bc81

Browse files
committed
fix($parse): stateful interceptors override an undefined expression
When using `$parse` with a stateful interceptor and the expression is `undefined`, then return the result from the interceptor Closes #9821
1 parent 031d4cd commit 3a3bc81

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/ng/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ function $ParseProvider() {
12181218
var result = interceptorFn(value, scope, locals);
12191219
// we only return the interceptor's result if the
12201220
// initial value is defined (for bind-once)
1221-
return isDefined(value) ? result : value;
1221+
return isDefined(value) || interceptorFn.$stateful ? result : value;
12221222
};
12231223

12241224
// Propagate $$watchDelegates other then inputsWatchDelegate

src/ng/rootScope.js

+3
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ function $RootScopeProvider(){
551551
newValue = _value;
552552
var newLength, key, bothNaN, newItem, oldItem;
553553

554+
// If the new value is undefined, then return undefined as the watch may be a one-time watch
555+
if (!isDefined(newValue)) return undefined;
556+
554557
if (!isObject(newValue)) { // if primitive
555558
if (oldValue !== newValue) {
556559
oldValue = newValue;

test/ng/compileSpec.js

+28
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,34 @@ describe('$compile', function() {
33543354
});
33553355
});
33563356

3357+
it('should continue with a digets cycle when there is a two-way binding from the child to the parent', function() {
3358+
module(function($controllerProvider) {
3359+
$controllerProvider.register('controllerWithWatch', function($scope) {
3360+
$scope.$watch('greeting', function(greeting) { $scope.text = greeting; });
3361+
});
3362+
directive('hello', function() {
3363+
return {
3364+
restrict: 'E',
3365+
scope: { greeting: '=' },
3366+
template: '<button ng-click="setGreeting()">Say hi!</button>',
3367+
link: function(scope) {
3368+
scope.setGreeting = function() { scope.greeting = 'Hello!'; };
3369+
}
3370+
};
3371+
});
3372+
});
3373+
3374+
inject(function($rootScope) {
3375+
compile('<div ng-controller="controllerWithWatch">' +
3376+
'<p>{{text}}</p>' +
3377+
'<div><hello greeting="greeting"></hello></div>' +
3378+
'</div>');
3379+
$rootScope.$digest();
3380+
browserTrigger(element.find('button'), 'click');
3381+
expect(element.find('p').text()).toBe('Hello!');
3382+
});
3383+
});
3384+
33573385
});
33583386

33593387

0 commit comments

Comments
 (0)