File tree 2 files changed +20
-5
lines changed
2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -182,23 +182,29 @@ function $InterpolateProvider() {
182
182
return concat . join ( '' ) ;
183
183
} ;
184
184
185
- var stringify = function ( value ) {
185
+ var getValue = function ( value ) {
186
186
if ( trustedContext ) {
187
187
value = $sce . getTrusted ( trustedContext , value ) ;
188
188
} else {
189
189
value = $sce . valueOf ( value ) ;
190
190
}
191
191
192
- if ( value === null || isUndefined ( value ) ) {
192
+ return value ;
193
+ } ;
194
+
195
+ var stringify = function ( value ) {
196
+ if ( isUndefined ( value ) || value === null ) {
193
197
value = '' ;
194
- } else if ( typeof value != 'string' ) {
198
+ }
199
+ if ( typeof value != 'string' ) {
195
200
value = toJson ( value ) ;
196
201
}
197
202
198
203
return value ;
199
204
} ;
200
205
201
- return extend ( function interpolationFn ( context ) {
206
+ return extend ( function interpolationFn ( context , strict ) {
207
+ strict = ! ! strict ;
202
208
var scopeId = context . $id || 'notAScope' ;
203
209
var lastValues = lastValuesCache . values [ scopeId ] ;
204
210
var lastResult = lastValuesCache . results [ scopeId ] ;
@@ -225,7 +231,11 @@ function $InterpolateProvider() {
225
231
226
232
try {
227
233
for ( ; i < ii ; i ++ ) {
228
- val = stringify ( parseFns [ i ] ( context ) ) ;
234
+ val = getValue ( parseFns [ i ] ( context ) ) ;
235
+ if ( strict && isUndefined ( val ) ) {
236
+ return ;
237
+ }
238
+ val = stringify ( val ) ;
229
239
if ( val !== lastValues [ i ] ) {
230
240
inputsChanged = true ;
231
241
}
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ describe('$interpolate', function() {
19
19
expect ( $interpolate ( 'some text' , true ) ) . toBeUndefined ( ) ;
20
20
} ) ) ;
21
21
22
+ it ( 'should return undefined when there are bindings and strict is set to true' ,
23
+ inject ( function ( $interpolate ) {
24
+ expect ( $interpolate ( 'test {{foo}}' ) ( { } , true ) ) . toBeUndefined ( ) ;
25
+ } ) ) ;
26
+
22
27
it ( 'should suppress falsy objects' , inject ( function ( $interpolate ) {
23
28
expect ( $interpolate ( '{{undefined}}' ) ( { } ) ) . toEqual ( '' ) ;
24
29
expect ( $interpolate ( '{{null}}' ) ( { } ) ) . toEqual ( '' ) ;
You can’t perform that action at this time.
0 commit comments