* @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)
| 13945 | * - `context`: evaluation context for all expressions embedded in the interpolated text |
| 13946 | */ |
| 13947 | function $interpolate(text, mustHaveExpression, trustedContext, allOrNothing) { |
| 13948 | var contextAllowsConcatenation = trustedContext === $sce.URL || trustedContext === $sce.MEDIA_URL; |
| 13949 | |
| 13950 | // Provide a quick exit and simplified result function for text with no interpolation |
| 13951 | if (!text.length || text.indexOf(startSymbol) === -1) { |
| 13952 | if (mustHaveExpression) return; |
| 13953 | |
| 13954 | var unescapedText = unescapeText(text); |
| 13955 | if (contextAllowsConcatenation) { |
| 13956 | unescapedText = $sce.getTrusted(trustedContext, unescapedText); |
| 13957 | } |
| 13958 | var constantInterp = valueFn(unescapedText); |
| 13959 | constantInterp.exp = text; |
| 13960 | constantInterp.expressions = []; |
| 13961 | constantInterp.$$watchDelegate = constantWatchDelegate; |
| 13962 | |
| 13963 | return constantInterp; |
| 13964 | } |
| 13965 | |
| 13966 | allOrNothing = !!allOrNothing; |
| 13967 | var startIndex, |
| 13968 | endIndex, |
| 13969 | index = 0, |
| 13970 | expressions = [], |
| 13971 | parseFns, |
| 13972 | textLength = text.length, |
| 13973 | exp, |
| 13974 | concat = [], |
| 13975 | expressionPositions = [], |
| 13976 | singleExpression; |
| 13977 | |
| 13978 | |
| 13979 | while (index < textLength) { |
| 13980 | if (((startIndex = text.indexOf(startSymbol, index)) !== -1) && |
| 13981 | ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) !== -1)) { |
| 13982 | if (index !== startIndex) { |
| 13983 | concat.push(unescapeText(text.substring(index, startIndex))); |
| 13984 | } |
| 13985 | exp = text.substring(startIndex + startSymbolLength, endIndex); |
| 13986 | expressions.push(exp); |
| 13987 | index = endIndex + endSymbolLength; |
| 13988 | expressionPositions.push(concat.length); |
| 13989 | concat.push(''); // Placeholder that will get replaced with the evaluated expression. |
| 13990 | } else { |
| 13991 | // we did not find an interpolation, so we have to add the remainder to the separators array |
| 13992 | if (index !== textLength) { |
| 13993 | concat.push(unescapeText(text.substring(index))); |
| 13994 | } |
| 13995 | break; |
| 13996 | } |
| 13997 | } |
| 13998 | |
| 13999 | singleExpression = concat.length === 1 && expressionPositions.length === 1; |
| 14000 | // Intercept expression if we need to stringify concatenated inputs, which may be SCE trusted |
| 14001 | // objects rather than simple strings |
| 14002 | // (we don't modify the expression if the input consists of only a single trusted input) |
| 14003 | var interceptor = contextAllowsConcatenation && singleExpression ? undefined : parseStringifyInterceptor; |
| 14004 | parseFns = expressions.map(function(exp) { return $parse(exp, interceptor); }); |
no test coverage detected