(node, directives, value, name, allOrNothing)
| 8118 | |
| 8119 | |
| 8120 | function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) { |
| 8121 | var trustedContext = getTrustedContext(node, name); |
| 8122 | allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing; |
| 8123 | |
| 8124 | var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing); |
| 8125 | |
| 8126 | // no interpolation found -> ignore |
| 8127 | if (!interpolateFn) return; |
| 8128 | |
| 8129 | |
| 8130 | if (name === "multiple" && nodeName_(node) === "select") { |
| 8131 | throw $compileMinErr("selmulti", |
| 8132 | "Binding to the 'multiple' attribute is not supported. Element: {0}", |
| 8133 | startingTag(node)); |
| 8134 | } |
| 8135 | |
| 8136 | directives.push({ |
| 8137 | priority: 100, |
| 8138 | compile: function() { |
| 8139 | return { |
| 8140 | pre: function attrInterpolatePreLinkFn(scope, element, attr) { |
| 8141 | var $$observers = (attr.$$observers || (attr.$$observers = {})); |
| 8142 | |
| 8143 | if (EVENT_HANDLER_ATTR_REGEXP.test(name)) { |
| 8144 | throw $compileMinErr('nodomevents', |
| 8145 | "Interpolations for HTML DOM event attributes are disallowed. Please use the " + |
| 8146 | "ng- versions (such as ng-click instead of onclick) instead."); |
| 8147 | } |
| 8148 | |
| 8149 | // If the attribute has changed since last $interpolate()ed |
| 8150 | var newValue = attr[name]; |
| 8151 | if (newValue !== value) { |
| 8152 | // we need to interpolate again since the attribute value has been updated |
| 8153 | // (e.g. by another directive's compile function) |
| 8154 | // ensure unset/empty values make interpolateFn falsy |
| 8155 | interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing); |
| 8156 | value = newValue; |
| 8157 | } |
| 8158 | |
| 8159 | // if attribute was updated so that there is no interpolation going on we don't want to |
| 8160 | // register any observers |
| 8161 | if (!interpolateFn) return; |
| 8162 | |
| 8163 | // initialize attr object so that it's ready in case we need the value for isolate |
| 8164 | // scope initialization, otherwise the value would not be available from isolate |
| 8165 | // directive's linking fn during linking phase |
| 8166 | attr[name] = interpolateFn(scope); |
| 8167 | |
| 8168 | ($$observers[name] || ($$observers[name] = [])).$$inter = true; |
| 8169 | (attr.$$observers && attr.$$observers[name].$$scope || scope). |
| 8170 | $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) { |
| 8171 | //special case for class attribute addition + removal |
| 8172 | //so that class changes can tap into the animation |
| 8173 | //hooks provided by the $animate service. Be sure to |
| 8174 | //skip animations when the first digest occurs (when |
| 8175 | //both the new and the old values are the same) since |
| 8176 | //the CSS classes are the non-interpolated values |
| 8177 | if (name === 'class' && newValue != oldValue) { |
no test coverage detected