Skip to content

Commit 0fb9f3b

Browse files
fix(ElementBinderBuilder): properly bind to web component properties
Fixes angular#776 Closes angular#1024
1 parent 81f3f32 commit 0fb9f3b

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

modules/angular2/src/core/compiler/pipeline/element_binder_builder.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,6 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
9393
return setterFn;
9494
}
9595

96-
const ROLE_ATTR = 'role';
97-
function roleSetter(element, value) {
98-
if (isString(value)) {
99-
DOM.setAttribute(element, ROLE_ATTR, value);
100-
} else {
101-
DOM.removeAttribute(element, ROLE_ATTR);
102-
if (isPresent(value)) {
103-
throw new BaseException("Invalid role attribute, only string values are allowed, got '" + stringify(value) + "'");
104-
}
105-
}
106-
}
10796

10897
/**
10998
* Creates the ElementBinders and adds watches to the
@@ -199,19 +188,19 @@ export class ElementBinderBuilder extends CompileStep {
199188
styleParts = StringWrapper.split(property, DOT_REGEXP);
200189
styleSuffix = styleParts.length > 2 ? ListWrapper.get(styleParts, 2) : '';
201190
setterFn = styleSetterFactory(ListWrapper.get(styleParts, 1), styleSuffix);
191+
} else if (StringWrapper.equals(property, 'innerHtml')) {
192+
setterFn = (element, value) => DOM.setInnerHTML(element, value);
202193
} else {
203194
property = this._resolvePropertyName(property);
204-
//TODO(pk): special casing innerHtml, see: https://github.com/angular/angular/issues/789
205-
if (StringWrapper.equals(property, 'innerHTML')) {
206-
setterFn = (element, value) => DOM.setInnerHTML(element, value);
207-
} else if (DOM.hasProperty(compileElement.element, property) || StringWrapper.equals(property, 'innerHtml')) {
208-
setterFn = reflector.setter(property);
195+
var propertySetterFn = reflector.setter(property);
196+
setterFn = function(receiver, value) {
197+
if (DOM.hasProperty(receiver, property)) {
198+
return propertySetterFn(receiver, value);
199+
}
209200
}
210201
}
211202

212-
if (isPresent(setterFn)) {
213-
protoView.bindElementProperty(expression.ast, property, setterFn);
214-
}
203+
protoView.bindElementProperty(expression.ast, property, setterFn);
215204
});
216205
}
217206

modules/angular2/test/core/compiler/integration_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ export function main() {
186186
});
187187
}));
188188

189+
it('should ignore bindings to unknown properties', inject([AsyncTestCompleter], (async) => {
190+
tplResolver.setTemplate(MyComp, new Template({inline: '<div unknown="{{ctxProp}}"></div>'}));
191+
192+
compiler.compile(MyComp).then((pv) => {
193+
createView(pv);
194+
195+
ctx.ctxProp = 'Some value';
196+
cd.detectChanges();
197+
expect(DOM.hasProperty(view.nodes[0], 'unknown')).toBeFalsy();
198+
199+
async.done();
200+
});
201+
}));
202+
189203
it('should consume directive watch expression change.', inject([AsyncTestCompleter], (async) => {
190204
var tpl =
191205
'<div>' +

modules/benchmarks/src/compiler/compiler_benchmark.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ function setupReflector() {
7878
"value0": (a,v) => a.value0 = v, "value1": (a,v) => a.value1 = v,
7979
"value2": (a,v) => a.value2 = v, "value3": (a,v) => a.value3 = v, "value4": (a,v) => a.value4 = v,
8080

81+
"attr0": (a,v) => a.attr0 = v, "attr1": (a,v) => a.attr1 = v,
82+
"attr2": (a,v) => a.attr2 = v, "attr3": (a,v) => a.attr3 = v, "attr4": (a,v) => a.attr4 = v,
83+
8184
"prop": (a,v) => a.prop = v
8285
});
8386
}

modules/benchmarks/src/naive_infinite_scroll/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export function setupReflector() {
139139
'aatStatusWidth': (o, v) => o.aatStatusWidth = v,
140140
'bundles': (o, v) => o.bundles = v,
141141
'bundlesWidth': (o, v) => o.bundlesWidth = v,
142+
'if': (o, v) => {},
143+
'of': (o, v) => {},
144+
'cellWidth': (o, v) => o.cellWidth = v,
142145
evt: (o, v) => null,
143146
'style': (o, m) => {
144147
//if (isBlank(m)) return;

modules/benchmarks/src/tree/tree_benchmark.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ function setupReflector() {
206206
'initData': (a,v) => a.initData = v,
207207
'data': (a,v) => a.data = v,
208208
'condition': (a,v) => a.condition = v,
209+
'if': (a,v) => a['if'] = v,
209210
});
210211
}
211212

0 commit comments

Comments
 (0)