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

Function addAttrInterpolateDirective

lib/test/angular/1.7.0/angular.js:10545–10612  ·  view source on GitHub ↗
(node, directives, value, name, isNgAttr)

Source from the content-addressed store, hash-verified

10543
10544
10545 function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {
10546 var trustedContext = getTrustedContext(node, name);
10547 var mustHaveExpression = !isNgAttr;
10548 var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;
10549
10550 var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);
10551
10552 // no interpolation found -> ignore
10553 if (!interpolateFn) return;
10554
10555 if (name === 'multiple' && nodeName_(node) === 'select') {
10556 throw $compileMinErr('selmulti',
10557 'Binding to the \'multiple\' attribute is not supported. Element: {0}',
10558 startingTag(node));
10559 }
10560
10561 if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
10562 throw $compileMinErr('nodomevents',
10563 'Interpolations for HTML DOM event attributes are disallowed. Please use the ' +
10564 'ng- versions (such as ng-click instead of onclick) instead.');
10565 }
10566
10567 directives.push({
10568 priority: 100,
10569 compile: function() {
10570 return {
10571 pre: function attrInterpolatePreLinkFn(scope, element, attr) {
10572 var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
10573
10574 // If the attribute has changed since last $interpolate()ed
10575 var newValue = attr[name];
10576 if (newValue !== value) {
10577 // we need to interpolate again since the attribute value has been updated
10578 // (e.g. by another directive's compile function)
10579 // ensure unset/empty values make interpolateFn falsy
10580 interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
10581 value = newValue;
10582 }
10583
10584 // if attribute was updated so that there is no interpolation going on we don't want to
10585 // register any observers
10586 if (!interpolateFn) return;
10587
10588 // initialize attr object so that it's ready in case we need the value for isolate
10589 // scope initialization, otherwise the value would not be available from isolate
10590 // directive's linking fn during linking phase
10591 attr[name] = interpolateFn(scope);
10592
10593 ($$observers[name] || ($$observers[name] = [])).$$inter = true;
10594 (attr.$$observers && attr.$$observers[name].$$scope || scope).
10595 $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
10596 //special case for class attribute addition + removal
10597 //so that class changes can tap into the animation
10598 //hooks provided by the $animate service. Be sure to
10599 //skip animations when the first digest occurs (when
10600 //both the new and the old values are the same) since
10601 //the CSS classes are the non-interpolated values
10602 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