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

Commit 91f21d6

Browse files
committed
fix($parse): do evaluate several times expressions with interceptors
For simple expressions without filters that need a stateless interceptor then handle the 2nd phase parse evaluation using `inputs`. Closes #12983
1 parent dc818e1 commit 91f21d6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/parse.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1906,13 +1906,14 @@ function $ParseProvider() {
19061906
function addInterceptor(parsedExpression, interceptorFn) {
19071907
if (!interceptorFn) return parsedExpression;
19081908
var watchDelegate = parsedExpression.$$watchDelegate;
1909+
var useInputs = false;
19091910

19101911
var regularWatch =
19111912
watchDelegate !== oneTimeLiteralWatchDelegate &&
19121913
watchDelegate !== oneTimeWatchDelegate;
19131914

19141915
var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) {
1915-
var value = parsedExpression(scope, locals, assign, inputs);
1916+
var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
19161917
return interceptorFn(value, scope, locals);
19171918
} : function oneTimeInterceptedExpression(scope, locals, assign, inputs) {
19181919
var value = parsedExpression(scope, locals, assign, inputs);
@@ -1930,6 +1931,7 @@ function $ParseProvider() {
19301931
// If there is an interceptor, but no watchDelegate then treat the interceptor like
19311932
// we treat filters - it is assumed to be a pure function unless flagged with $stateful
19321933
fn.$$watchDelegate = inputsWatchDelegate;
1934+
useInputs = !parsedExpression.inputs;
19331935
fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
19341936
}
19351937

test/ng/compileSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,14 @@ describe('$compile', function() {
947947
expect(child).toHaveClass('log'); // merged from replace directive template
948948
}));
949949

950+
it('should interpolate the values once per digest',
951+
inject(function($compile, $rootScope, log) {
952+
element = $compile('<div>{{log("A")}} foo {{::log("B")}}</div>')($rootScope);
953+
$rootScope.log = log;
954+
$rootScope.$digest();
955+
expect(log).toEqual('A; B; A; B');
956+
}));
957+
950958
it('should update references to replaced jQuery context', function() {
951959
module(function($compileProvider) {
952960
$compileProvider.directive('foo', function() {

0 commit comments

Comments
 (0)