Skip to content

Commit fbfa14a

Browse files
fix($compile): support merging special attribute names in replace directives
When compiling a `replace` directive, the compiler merges the attributes from the replaced element onto the template element. Unfortunately, `setAttribute` and other related DOM methods do not allow certain attribute names - in particular Angular 2 style names such as `(click)` and `[value]`. This is relevant when using ngForward with Angular Material, since the `mgButton` directive uses `replace` and in the former you often use `(click)`. This fixes the problem but for those special attributes the speed is considerably slow. Closes angular#13317 Closes angular#13318
1 parent 3450d1b commit fbfa14a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ng/compile.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1229,11 +1229,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
12291229
};
12301230

12311231
function setSpecialAttr(element, attrName, value) {
1232-
specialAttrHolder.innerHTML = "<span " + attrName + "='" + (value || '').replace(QUOTE_REGEX, '&quot;') + "'>"
1232+
// Attributes names that do not start with letters cannot be set using `setAttribute`
1233+
// so we have to jump through some hoops to get such an attribute
1234+
// https://github.com/angular/angular.js/pull/13318
1235+
specialAttrHolder.innerHTML = "<span " + attrName + ">";
12331236
var span = specialAttrHolder.firstChild;
12341237
var attribute = span.attributes[0];
12351238
// We have to remove the attribute from the holder element before we can add it to the destination element
12361239
span.removeAttribute(attrName);
1240+
attribute.value = value;
12371241
element.attributes.setNamedItem(attribute);
12381242
}
12391243

0 commit comments

Comments
 (0)