Skip to content

Commit 3450d1b

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
1 parent 4b7ef77 commit 3450d1b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/ng/compile.js

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

12311231
function setSpecialAttr(element, attrName, value) {
1232-
specialAttrHolder.innerHTML = "<span " + attrName + "='" + (value || '').replace(QUOTE_REGEX, '&quot;') + "'>";
1233-
var attribute = specialAttrHolder.firstChild.attributes[0].cloneNode();
1232+
specialAttrHolder.innerHTML = "<span " + attrName + "='" + (value || '').replace(QUOTE_REGEX, '&quot;') + "'>"
1233+
var span = specialAttrHolder.firstChild;
1234+
var attribute = span.attributes[0];
1235+
// We have to remove the attribute from the holder element before we can add it to the destination element
1236+
span.removeAttribute(attrName);
12341237
element.attributes.setNamedItem(attribute);
12351238
}
12361239

0 commit comments

Comments
 (0)