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

Commit ed99821

Browse files
lgalfasoIgorMinar
authored andcommitted
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 NOTE from Igor: this is not the best solution. We need to refactor this and one-time + $interpolate code to properly fix this. @caitp is on it. See discussion in the PR. Closes #9821 Closes #9825
1 parent e057a9a commit ed99821

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
@@ -1257,7 +1257,7 @@ function $ParseProvider() {
12571257
var result = interceptorFn(value, scope, locals);
12581258
// we only return the interceptor's result if the
12591259
// initial value is defined (for bind-once)
1260-
return isDefined(value) ? result : value;
1260+
return isDefined(value) || interceptorFn.$stateful ? result : value;
12611261
};
12621262

12631263
// Propagate $$watchDelegates other then inputsWatchDelegate

src/ng/rootScope.js

+3
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ function $RootScopeProvider() {
555555
newValue = _value;
556556
var newLength, key, bothNaN, newItem, oldItem;
557557

558+
// If the new value is undefined, then return undefined as the watch may be a one-time watch
559+
if (isUndefined(newValue)) return;
560+
558561
if (!isObject(newValue)) { // if primitive
559562
if (oldValue !== newValue) {
560563
oldValue = newValue;

test/ng/compileSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -3367,6 +3367,31 @@ describe('$compile', function() {
33673367
});
33683368
});
33693369

3370+
it('should continue with a digets cycle when there is a two-way binding from the child to the parent', function() {
3371+
module(function() {
3372+
directive('hello', function() {
3373+
return {
3374+
restrict: 'E',
3375+
scope: { greeting: '=' },
3376+
template: '<button ng-click="setGreeting()">Say hi!</button>',
3377+
link: function(scope) {
3378+
scope.setGreeting = function() { scope.greeting = 'Hello!'; };
3379+
}
3380+
};
3381+
});
3382+
});
3383+
3384+
inject(function($rootScope) {
3385+
compile('<div>' +
3386+
'<p>{{greeting}}</p>' +
3387+
'<div><hello greeting="greeting"></hello></div>' +
3388+
'</div>');
3389+
$rootScope.$digest();
3390+
browserTrigger(element.find('button'), 'click');
3391+
expect(element.find('p').text()).toBe('Hello!');
3392+
});
3393+
});
3394+
33703395
});
33713396

33723397

0 commit comments

Comments
 (0)