(node, directives, value, name, isNgAttr)
| 9995 | |
| 9996 | |
| 9997 | function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) { |
| 9998 | var trustedContext = getTrustedContext(node, name); |
| 9999 | var mustHaveExpression = !isNgAttr; |
| 10000 | var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr; |
| 10001 | |
| 10002 | var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing); |
| 10003 | |
| 10004 | // no interpolation found -> ignore |
| 10005 | if (!interpolateFn) return; |
| 10006 | |
| 10007 | if (name === 'multiple' && nodeName_(node) === 'select') { |
| 10008 | throw $compileMinErr('selmulti', |
| 10009 | 'Binding to the \'multiple\' attribute is not supported. Element: {0}', |
| 10010 | startingTag(node)); |
| 10011 | } |
| 10012 | |
| 10013 | directives.push({ |
| 10014 | priority: 100, |
| 10015 | compile: function() { |
| 10016 | return { |
| 10017 | pre: function attrInterpolatePreLinkFn(scope, element, attr) { |
| 10018 | var $$observers = (attr.$$observers || (attr.$$observers = createMap())); |
| 10019 | |
| 10020 | if (EVENT_HANDLER_ATTR_REGEXP.test(name)) { |
| 10021 | throw $compileMinErr('nodomevents', |
| 10022 | 'Interpolations for HTML DOM event attributes are disallowed. Please use the ' + |
| 10023 | 'ng- versions (such as ng-click instead of onclick) instead.'); |
| 10024 | } |
| 10025 | |
| 10026 | // If the attribute has changed since last $interpolate()ed |
| 10027 | var newValue = attr[name]; |
| 10028 | if (newValue !== value) { |
| 10029 | // we need to interpolate again since the attribute value has been updated |
| 10030 | // (e.g. by another directive's compile function) |
| 10031 | // ensure unset/empty values make interpolateFn falsy |
| 10032 | interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing); |
| 10033 | value = newValue; |
| 10034 | } |
| 10035 | |
| 10036 | // if attribute was updated so that there is no interpolation going on we don't want to |
| 10037 | // register any observers |
| 10038 | if (!interpolateFn) return; |
| 10039 | |
| 10040 | // initialize attr object so that it's ready in case we need the value for isolate |
| 10041 | // scope initialization, otherwise the value would not be available from isolate |
| 10042 | // directive's linking fn during linking phase |
| 10043 | attr[name] = interpolateFn(scope); |
| 10044 | |
| 10045 | ($$observers[name] || ($$observers[name] = [])).$$inter = true; |
| 10046 | (attr.$$observers && attr.$$observers[name].$$scope || scope). |
| 10047 | $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) { |
| 10048 | //special case for class attribute addition + removal |
| 10049 | //so that class changes can tap into the animation |
| 10050 | //hooks provided by the $animate service. Be sure to |
| 10051 | //skip animations when the first digest occurs (when |
| 10052 | //both the new and the old values are the same) since |
| 10053 | //the CSS classes are the non-interpolated values |
| 10054 | if (name === 'class' && newValue !== oldValue) { |
no test coverage detected