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

Commit 8871964

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 8871964

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-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 (isUndefined(newValue)) return;
556+
554557
if (!isObject(newValue)) { // if primitive
555558
if (oldValue !== newValue) {
556559
oldValue = newValue;

test/ng/compileSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,31 @@ 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() {
3359+
directive('hello', function() {
3360+
return {
3361+
restrict: 'E',
3362+
scope: { greeting: '=' },
3363+
template: '<button ng-click="setGreeting()">Say hi!</button>',
3364+
link: function(scope) {
3365+
scope.setGreeting = function() { scope.greeting = 'Hello!'; };
3366+
}
3367+
};
3368+
});
3369+
});
3370+
3371+
inject(function($rootScope) {
3372+
compile('<div>' +
3373+
'<p>{{greeting}}</p>' +
3374+
'<div><hello greeting="greeting"></hello></div>' +
3375+
'</div>');
3376+
$rootScope.$digest();
3377+
browserTrigger(element.find('button'), 'click');
3378+
expect(element.find('p').text()).toBe('Hello!');
3379+
});
3380+
});
3381+
33573382
});
33583383

33593384

0 commit comments

Comments
 (0)