MCPcopy
hub / github.com/angular-ui/ui-router / addAttrInterpolateDirective

Function addAttrInterpolateDirective

test/angular/1.7/angular.js:11115–11181  ·  view source on GitHub ↗
(node, directives, value, name, isNgAttr)

Source from the content-addressed store, hash-verified

11113 }
11114
11115 function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {
11116 var nodeName = nodeName_(node);
11117 var trustedContext = getTrustedAttrContext(nodeName, name);
11118 var mustHaveExpression = !isNgAttr;
11119 var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;
11120
11121 var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);
11122
11123 // no interpolation found -> ignore
11124 if (!interpolateFn) return;
11125
11126 if (name === 'multiple' && nodeName === 'select') {
11127 throw $compileMinErr('selmulti',
11128 'Binding to the \'multiple\' attribute is not supported. Element: {0}',
11129 startingTag(node));
11130 }
11131
11132 if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
11133 throw $compileMinErr('nodomevents', 'Interpolations for HTML DOM event attributes are disallowed');
11134 }
11135
11136 directives.push({
11137 priority: 100,
11138 compile: function() {
11139 return {
11140 pre: function attrInterpolatePreLinkFn(scope, element, attr) {
11141 var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
11142
11143 // If the attribute has changed since last $interpolate()ed
11144 var newValue = attr[name];
11145 if (newValue !== value) {
11146 // we need to interpolate again since the attribute value has been updated
11147 // (e.g. by another directive's compile function)
11148 // ensure unset/empty values make interpolateFn falsy
11149 interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
11150 value = newValue;
11151 }
11152
11153 // if attribute was updated so that there is no interpolation going on we don't want to
11154 // register any observers
11155 if (!interpolateFn) return;
11156
11157 // initialize attr object so that it's ready in case we need the value for isolate
11158 // scope initialization, otherwise the value would not be available from isolate
11159 // directive's linking fn during linking phase
11160 attr[name] = interpolateFn(scope);
11161
11162 ($$observers[name] || ($$observers[name] = [])).$$inter = true;
11163 (attr.$$observers && attr.$$observers[name].$$scope || scope).
11164 $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
11165 //special case for class attribute addition + removal
11166 //so that class changes can tap into the animation
11167 //hooks provided by the $animate service. Be sure to
11168 //skip animations when the first digest occurs (when
11169 //both the new and the old values are the same) since
11170 //the CSS classes are the non-interpolated values
11171 if (name === 'class' && newValue !== oldValue) {
11172 attr.$updateClass(newValue, oldValue);

Callers 1

collectDirectivesFunction · 0.70

Calls 5

getTrustedAttrContextFunction · 0.85
nodeName_Function · 0.70
$interpolateFunction · 0.70
startingTagFunction · 0.70
createMapFunction · 0.70

Tested by

no test coverage detected