Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c93d5cf

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 #13317 Closes #13318
1 parent f84a1bd commit c93d5cf

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/ng/compile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
12321232
// so we have to jump through some hoops to get such an attribute
12331233
// https://github.com/angular/angular.js/pull/13318
12341234
specialAttrHolder.innerHTML = "<span " + attrName + ">";
1235-
var span = specialAttrHolder.firstChild;
1236-
var attribute = span.attributes[0];
1237-
// We have to remove the attribute from the holder element before we can add it to the destination element
1238-
span.removeAttribute(attrName);
1235+
var attributes = specialAttrHolder.firstChild.attributes;
1236+
var attribute = attributes[0];
1237+
// We have to remove the attribute from its container element before we can add it to the destination element
1238+
attributes.removeNamedItem(attribute.name);
12391239
attribute.value = value;
12401240
element.attributes.setNamedItem(attribute);
12411241
}

test/ng/compileSpec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,11 @@ describe('$compile', function() {
871871

872872
it('should correctly merge attributes that contain special characters', inject(function($compile, $rootScope) {
873873
element = $compile(
874-
'<div><div replace (click)="doSomething()" [value]="someExpression"></div><div>')($rootScope);
874+
'<div><div replace (click)="doSomething()" [value]="someExpression" Ω="omega"></div><div>')($rootScope);
875875
var div = element.find('div');
876876
expect(div.attr('(click)')).toEqual('doSomething()');
877877
expect(div.attr('[value]')).toEqual('someExpression');
878+
expect(div.attr('Ω')).toEqual('omega');
878879
}));
879880

880881

0 commit comments

Comments
 (0)