(node, directives, value, name, allOrNothing)
| 8485 | |
| 8486 | |
| 8487 | function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) { |
| 8488 | var trustedContext = getTrustedContext(node, name); |
| 8489 | allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing; |
| 8490 | |
| 8491 | var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing); |
| 8492 | |
| 8493 | // no interpolation found -> ignore |
| 8494 | if (!interpolateFn) return; |
| 8495 | |
| 8496 | |
| 8497 | if (name === "multiple" && nodeName_(node) === "select") { |
| 8498 | throw $compileMinErr("selmulti", |
| 8499 | "Binding to the 'multiple' attribute is not supported. Element: {0}", |
| 8500 | startingTag(node)); |
| 8501 | } |
| 8502 | |
| 8503 | directives.push({ |
| 8504 | priority: 100, |
| 8505 | compile: function() { |
| 8506 | return { |
| 8507 | pre: function attrInterpolatePreLinkFn(scope, element, attr) { |
| 8508 | var $$observers = (attr.$$observers || (attr.$$observers = {})); |
| 8509 | |
| 8510 | if (EVENT_HANDLER_ATTR_REGEXP.test(name)) { |
| 8511 | throw $compileMinErr('nodomevents', |
| 8512 | "Interpolations for HTML DOM event attributes are disallowed. Please use the " + |
| 8513 | "ng- versions (such as ng-click instead of onclick) instead."); |
| 8514 | } |
| 8515 | |
| 8516 | // If the attribute has changed since last $interpolate()ed |
| 8517 | var newValue = attr[name]; |
| 8518 | if (newValue !== value) { |
| 8519 | // we need to interpolate again since the attribute value has been updated |
| 8520 | // (e.g. by another directive's compile function) |
| 8521 | // ensure unset/empty values make interpolateFn falsy |
| 8522 | interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing); |
| 8523 | value = newValue; |
| 8524 | } |
| 8525 | |
| 8526 | // if attribute was updated so that there is no interpolation going on we don't want to |
| 8527 | // register any observers |
| 8528 | if (!interpolateFn) return; |
| 8529 | |
| 8530 | // initialize attr object so that it's ready in case we need the value for isolate |
| 8531 | // scope initialization, otherwise the value would not be available from isolate |
| 8532 | // directive's linking fn during linking phase |
| 8533 | attr[name] = interpolateFn(scope); |
| 8534 | |
| 8535 | ($$observers[name] || ($$observers[name] = [])).$$inter = true; |
| 8536 | (attr.$$observers && attr.$$observers[name].$$scope || scope). |
| 8537 | $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) { |
| 8538 | //special case for class attribute addition + removal |
| 8539 | //so that class changes can tap into the animation |
| 8540 | //hooks provided by the $animate service. Be sure to |
| 8541 | //skip animations when the first digest occurs (when |
| 8542 | //both the new and the old values are the same) since |
| 8543 | //the CSS classes are the non-interpolated values |
| 8544 | if (name === 'class' && newValue != oldValue) { |
no test coverage detected