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