MCPcopy Create free account
hub / github.com/apache/cloudstack / $interpolate

Function $interpolate

tools/ngui/static/js/lib/angular.js:4940–4992  ·  view source on GitHub ↗

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

(text, mustHaveExpression)

Source from the content-addressed store, hash-verified

4938 *
4939 */
4940 function $interpolate(text, mustHaveExpression) {
4941 var startIndex,
4942 endIndex,
4943 index = 0,
4944 parts = [],
4945 length = text.length,
4946 hasInterpolation = false,
4947 fn,
4948 exp,
4949 concat = [];
4950
4951 while(index < length) {
4952 if ( ((startIndex = text.indexOf(startSymbol, index)) != -1) &&
4953 ((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1) ) {
4954 (index != startIndex) && parts.push(text.substring(index, startIndex));
4955 parts.push(fn = $parse(exp = text.substring(startIndex + startSymbolLength, endIndex)));
4956 fn.exp = exp;
4957 index = endIndex + endSymbolLength;
4958 hasInterpolation = true;
4959 } else {
4960 // we did not find anything, so we have to add the remainder to the parts array
4961 (index != length) && parts.push(text.substring(index));
4962 index = length;
4963 }
4964 }
4965
4966 if (!(length = parts.length)) {
4967 // we added, nothing, must have been an empty string.
4968 parts.push('');
4969 length = 1;
4970 }
4971
4972 if (!mustHaveExpression || hasInterpolation) {
4973 concat.length = length;
4974 fn = function(context) {
4975 for(var i = 0, ii = length, part; i<ii; i++) {
4976 if (typeof (part = parts[i]) == 'function') {
4977 part = part(context);
4978 if (part == null || part == undefined) {
4979 part = '';
4980 } else if (typeof part != 'string') {
4981 part = toJson(part);
4982 }
4983 }
4984 concat[i] = part;
4985 }
4986 return concat.join('');
4987 };
4988 fn.exp = text;
4989 fn.parts = parts;
4990 return fn;
4991 }
4992 }
4993
4994
4995 /**

Callers 3

angular.jsFile · 0.85

Calls 2

toJsonFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected