Skip to content

Commit 3785724

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 ee8e22a commit 3785724

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

src/ng/compile.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,25 +1232,12 @@ 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-
console.log('holder');
1236-
console.log(specialAttrHolder);
12371235
var attributes = specialAttrHolder.firstChild.attributes;
12381236
var attribute = attributes[0];
1239-
console.log('attribute');
1240-
console.log(attribute, attribute.name, attribute.value);
12411237
// We have to remove the attribute from its container element before we can add it to the destination element
12421238
attributes.removeNamedItem(attribute.name);
12431239
attribute.value = value;
1244-
console.log('attribute with value');
1245-
console.log(attribute, attribute.name, attribute.value);
12461240
element.attributes.setNamedItem(attribute);
1247-
console.log('element attributes');
1248-
for(var i=0; i< element.attributes.length; i++) {
1249-
var attribute = element.attributes[i];
1250-
console.log(attribute, attribute.name, attribute.value);
1251-
}
1252-
console.log('element');
1253-
console.log(element);
12541241
}
12551242

12561243
function safeAddClass($element, className) {

test/ng/compileSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,11 +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" Ω="omega"></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');
878+
expect(div.attr('ω')).toEqual('omega');
879879
}));
880880

881881

0 commit comments

Comments
 (0)