(node, directives, value, name)
| 7068 | |
| 7069 | |
| 7070 | function addAttrInterpolateDirective(node, directives, value, name) { |
| 7071 | var interpolateFn = $interpolate(value, true); |
| 7072 | |
| 7073 | // no interpolation found -> ignore |
| 7074 | if (!interpolateFn) return; |
| 7075 | |
| 7076 | |
| 7077 | if (name === "multiple" && nodeName_(node) === "SELECT") { |
| 7078 | throw $compileMinErr("selmulti", |
| 7079 | "Binding to the 'multiple' attribute is not supported. Element: {0}", |
| 7080 | startingTag(node)); |
| 7081 | } |
| 7082 | |
| 7083 | directives.push({ |
| 7084 | priority: 100, |
| 7085 | compile: function() { |
| 7086 | return { |
| 7087 | pre: function attrInterpolatePreLinkFn(scope, element, attr) { |
| 7088 | var $$observers = (attr.$$observers || (attr.$$observers = {})); |
| 7089 | |
| 7090 | if (EVENT_HANDLER_ATTR_REGEXP.test(name)) { |
| 7091 | throw $compileMinErr('nodomevents', |
| 7092 | "Interpolations for HTML DOM event attributes are disallowed. Please use the " + |
| 7093 | "ng- versions (such as ng-click instead of onclick) instead."); |
| 7094 | } |
| 7095 | |
| 7096 | // we need to interpolate again, in case the attribute value has been updated |
| 7097 | // (e.g. by another directive's compile function) |
| 7098 | interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name)); |
| 7099 | |
| 7100 | // if attribute was updated so that there is no interpolation going on we don't want to |
| 7101 | // register any observers |
| 7102 | if (!interpolateFn) return; |
| 7103 | |
| 7104 | // TODO(i): this should likely be attr.$set(name, iterpolateFn(scope) so that we reset the |
| 7105 | // actual attr value |
| 7106 | attr[name] = interpolateFn(scope); |
| 7107 | ($$observers[name] || ($$observers[name] = [])).$$inter = true; |
| 7108 | (attr.$$observers && attr.$$observers[name].$$scope || scope). |
| 7109 | $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) { |
| 7110 | //special case for class attribute addition + removal |
| 7111 | //so that class changes can tap into the animation |
| 7112 | //hooks provided by the $animate service. Be sure to |
| 7113 | //skip animations when the first digest occurs (when |
| 7114 | //both the new and the old values are the same) since |
| 7115 | //the CSS classes are the non-interpolated values |
| 7116 | if(name === 'class' && newValue != oldValue) { |
| 7117 | attr.$updateClass(newValue, oldValue); |
| 7118 | } else { |
| 7119 | attr.$set(name, newValue); |
| 7120 | } |
| 7121 | }); |
| 7122 | } |
| 7123 | }; |
| 7124 | } |
| 7125 | }); |
| 7126 | } |
| 7127 |
no test coverage detected