(node, directives, value, name, isNgAttr)
| 11178 | } |
| 11179 | |
| 11180 | function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) { |
| 11181 | var nodeName = nodeName_(node); |
| 11182 | var trustedContext = getTrustedAttrContext(nodeName, name); |
| 11183 | var mustHaveExpression = !isNgAttr; |
| 11184 | var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr; |
| 11185 | |
| 11186 | var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing); |
| 11187 | |
| 11188 | // no interpolation found -> ignore |
| 11189 | if (!interpolateFn) return; |
| 11190 | |
| 11191 | if (name === 'multiple' && nodeName === 'select') { |
| 11192 | throw $compileMinErr('selmulti', |
| 11193 | 'Binding to the \'multiple\' attribute is not supported. Element: {0}', |
| 11194 | startingTag(node)); |
| 11195 | } |
| 11196 | |
| 11197 | if (EVENT_HANDLER_ATTR_REGEXP.test(name)) { |
| 11198 | throw $compileMinErr('nodomevents', 'Interpolations for HTML DOM event attributes are disallowed'); |
| 11199 | } |
| 11200 | |
| 11201 | directives.push({ |
| 11202 | priority: 100, |
| 11203 | compile: function() { |
| 11204 | return { |
| 11205 | pre: function attrInterpolatePreLinkFn(scope, element, attr) { |
| 11206 | var $$observers = (attr.$$observers || (attr.$$observers = createMap())); |
| 11207 | |
| 11208 | // If the attribute has changed since last $interpolate()ed |
| 11209 | var newValue = attr[name]; |
| 11210 | if (newValue !== value) { |
| 11211 | // we need to interpolate again since the attribute value has been updated |
| 11212 | // (e.g. by another directive's compile function) |
| 11213 | // ensure unset/empty values make interpolateFn falsy |
| 11214 | interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing); |
| 11215 | value = newValue; |
| 11216 | } |
| 11217 | |
| 11218 | // if attribute was updated so that there is no interpolation going on we don't want to |
| 11219 | // register any observers |
| 11220 | if (!interpolateFn) return; |
| 11221 | |
| 11222 | // initialize attr object so that it's ready in case we need the value for isolate |
| 11223 | // scope initialization, otherwise the value would not be available from isolate |
| 11224 | // directive's linking fn during linking phase |
| 11225 | attr[name] = interpolateFn(scope); |
| 11226 | |
| 11227 | ($$observers[name] || ($$observers[name] = [])).$$inter = true; |
| 11228 | (attr.$$observers && attr.$$observers[name].$$scope || scope). |
| 11229 | $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) { |
| 11230 | //special case for class attribute addition + removal |
| 11231 | //so that class changes can tap into the animation |
| 11232 | //hooks provided by the $animate service. Be sure to |
| 11233 | //skip animations when the first digest occurs (when |
| 11234 | //both the new and the old values are the same) since |
| 11235 | //the CSS classes are the non-interpolated values |
| 11236 | if (name === 'class' && newValue !== oldValue) { |
| 11237 | attr.$updateClass(newValue, oldValue); |
no test coverage detected