MCPcopy
hub / github.com/angular-ui/ui-router / $interpolate

Function $interpolate

test/angular/1.7/angular.js:13882–14016  ·  view source on GitHub ↗

* @ngdoc service * @name $interpolate * @kind function * * @requires $parse * @requires $sce * * @description * * Compiles a string with markup into an interpolation function. This service is used by the * HTML ng.$compile $compile service fo

(text, mustHaveExpression, trustedContext, allOrNothing)

Source from the content-addressed store, hash-verified

13880 * - `context`: evaluation context for all expressions embedded in the interpolated text
13881 */
13882 function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) {
13883 var contextAllowsConcatenation = trustedContext === $sce.URL || trustedContext === $sce.MEDIA_URL;
13884
13885 // Provide a quick exit and simplified result function for text with no interpolation
13886 if (!text.length || text.indexOf(startSymbol) === -1) {
13887 if (mustHaveExpression) return;
13888
13889 var unescapedText = unescapeText(text);
13890 if (contextAllowsConcatenation) {
13891 unescapedText = $sce.getTrusted(trustedContext, unescapedText);
13892 }
13893 var constantInterp = valueFn(unescapedText);
13894 constantInterp.exp = text;
13895 constantInterp.expressions = [];
13896 constantInterp.$$watchDelegate = constantWatchDelegate;
13897
13898 return constantInterp;
13899 }
13900
13901 allOrNothing = !!allOrNothing;
13902 var startIndex,
13903 endIndex,
13904 index = 0,
13905 expressions = [],
13906 parseFns,
13907 textLength = text.length,
13908 exp,
13909 concat = [],
13910 expressionPositions = [],
13911 singleExpression;
13912
13913
13914 while (index < textLength) {
13915 if (((startIndex = text.indexOf(startSymbol, index)) !== -1) &&
13916 ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) !== -1)) {
13917 if (index !== startIndex) {
13918 concat.push(unescapeText(text.substring(index, startIndex)));
13919 }
13920 exp = text.substring(startIndex + startSymbolLength, endIndex);
13921 expressions.push(exp);
13922 index = endIndex + endSymbolLength;
13923 expressionPositions.push(concat.length);
13924 concat.push(''); // Placeholder that will get replaced with the evaluated expression.
13925 } else {
13926 // we did not find an interpolation, so we have to add the remainder to the separators array
13927 if (index !== textLength) {
13928 concat.push(unescapeText(text.substring(index)));
13929 }
13930 break;
13931 }
13932 }
13933
13934 singleExpression = concat.length === 1 && expressionPositions.length === 1;
13935 // Intercept expression if we need to stringify concatenated inputs, which may be SCE trusted
13936 // objects rather than simple strings
13937 // (we don't modify the expression if the input consists of only a single trusted input)
13938 var interceptor = contextAllowsConcatenation && singleExpression ? undefined : parseStringifyInterceptor;
13939 parseFns = expressions.map(function(exp) { return $parse(exp, interceptor); });

Callers 7

FormControllerFunction · 0.70
angular.jsFile · 0.70
NgModelControllerFunction · 0.70
angular-animate.jsFile · 0.70

Calls 5

unescapeTextFunction · 0.70
valueFnFunction · 0.70
$parseFunction · 0.70
extendFunction · 0.70
computeFunction · 0.70

Tested by

no test coverage detected