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

Function addAttrInterpolateDirective

lib/test/angular/1.6.7/angular.js:10456–10523  ·  view source on GitHub ↗
(node, directives, value, name, isNgAttr)

Source from the content-addressed store, hash-verified

10454
10455
10456 function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {
10457 var trustedContext = getTrustedContext(node, name);
10458 var mustHaveExpression = !isNgAttr;
10459 var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;
10460
10461 var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);
10462
10463 // no interpolation found -> ignore
10464 if (!interpolateFn) return;
10465
10466 if (name === 'multiple' && nodeName_(node) === 'select') {
10467 throw $compileMinErr('selmulti',
10468 'Binding to the \'multiple\' attribute is not supported. Element: {0}',
10469 startingTag(node));
10470 }
10471
10472 if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
10473 throw $compileMinErr('nodomevents',
10474 'Interpolations for HTML DOM event attributes are disallowed. Please use the ' +
10475 'ng- versions (such as ng-click instead of onclick) instead.');
10476 }
10477
10478 directives.push({
10479 priority: 100,
10480 compile: function() {
10481 return {
10482 pre: function attrInterpolatePreLinkFn(scope, element, attr) {
10483 var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
10484
10485 // If the attribute has changed since last $interpolate()ed
10486 var newValue = attr[name];
10487 if (newValue !== value) {
10488 // we need to interpolate again since the attribute value has been updated
10489 // (e.g. by another directive's compile function)
10490 // ensure unset/empty values make interpolateFn falsy
10491 interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
10492 value = newValue;
10493 }
10494
10495 // if attribute was updated so that there is no interpolation going on we don't want to
10496 // register any observers
10497 if (!interpolateFn) return;
10498
10499 // initialize attr object so that it's ready in case we need the value for isolate
10500 // scope initialization, otherwise the value would not be available from isolate
10501 // directive's linking fn during linking phase
10502 attr[name] = interpolateFn(scope);
10503
10504 ($$observers[name] || ($$observers[name] = [])).$$inter = true;
10505 (attr.$$observers && attr.$$observers[name].$$scope || scope).
10506 $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
10507 //special case for class attribute addition + removal
10508 //so that class changes can tap into the animation
10509 //hooks provided by the $animate service. Be sure to
10510 //skip animations when the first digest occurs (when
10511 //both the new and the old values are the same) since
10512 //the CSS classes are the non-interpolated values
10513 if (name === 'class' && newValue !== oldValue) {

Callers 1

collectDirectivesFunction · 0.70

Calls 5

getTrustedContextFunction · 0.70
$interpolateFunction · 0.70
nodeName_Function · 0.70
startingTagFunction · 0.70
createMapFunction · 0.70

Tested by

no test coverage detected