fix(ElementBinderBuilder): properly bind to web component properties
Fixes #776 Closes #1024
This commit is contained in:
parent
81f3f32217
commit
0fb9f3bd6c
|
@ -93,17 +93,6 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
|
|||
return setterFn;
|
||||
}
|
||||
|
||||
const ROLE_ATTR = 'role';
|
||||
function roleSetter(element, value) {
|
||||
if (isString(value)) {
|
||||
DOM.setAttribute(element, ROLE_ATTR, value);
|
||||
} else {
|
||||
DOM.removeAttribute(element, ROLE_ATTR);
|
||||
if (isPresent(value)) {
|
||||
throw new BaseException("Invalid role attribute, only string values are allowed, got '" + stringify(value) + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ElementBinders and adds watches to the
|
||||
|
@ -199,19 +188,19 @@ export class ElementBinderBuilder extends CompileStep {
|
|||
styleParts = StringWrapper.split(property, DOT_REGEXP);
|
||||
styleSuffix = styleParts.length > 2 ? ListWrapper.get(styleParts, 2) : '';
|
||||
setterFn = styleSetterFactory(ListWrapper.get(styleParts, 1), styleSuffix);
|
||||
} else if (StringWrapper.equals(property, 'innerHtml')) {
|
||||
setterFn = (element, value) => DOM.setInnerHTML(element, value);
|
||||
} else {
|
||||
property = this._resolvePropertyName(property);
|
||||
//TODO(pk): special casing innerHtml, see: https://github.com/angular/angular/issues/789
|
||||
if (StringWrapper.equals(property, 'innerHTML')) {
|
||||
setterFn = (element, value) => DOM.setInnerHTML(element, value);
|
||||
} else if (DOM.hasProperty(compileElement.element, property) || StringWrapper.equals(property, 'innerHtml')) {
|
||||
setterFn = reflector.setter(property);
|
||||
var propertySetterFn = reflector.setter(property);
|
||||
setterFn = function(receiver, value) {
|
||||
if (DOM.hasProperty(receiver, property)) {
|
||||
return propertySetterFn(receiver, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isPresent(setterFn)) {
|
||||
protoView.bindElementProperty(expression.ast, property, setterFn);
|
||||
}
|
||||
protoView.bindElementProperty(expression.ast, property, setterFn);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -186,6 +186,20 @@ export function main() {
|
|||
});
|
||||
}));
|
||||
|
||||
it('should ignore bindings to unknown properties', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setTemplate(MyComp, new Template({inline: '<div unknown="{{ctxProp}}"></div>'}));
|
||||
|
||||
compiler.compile(MyComp).then((pv) => {
|
||||
createView(pv);
|
||||
|
||||
ctx.ctxProp = 'Some value';
|
||||
cd.detectChanges();
|
||||
expect(DOM.hasProperty(view.nodes[0], 'unknown')).toBeFalsy();
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should consume directive watch expression change.', inject([AsyncTestCompleter], (async) => {
|
||||
var tpl =
|
||||
'<div>' +
|
||||
|
|
|
@ -78,6 +78,9 @@ function setupReflector() {
|
|||
"value0": (a,v) => a.value0 = v, "value1": (a,v) => a.value1 = v,
|
||||
"value2": (a,v) => a.value2 = v, "value3": (a,v) => a.value3 = v, "value4": (a,v) => a.value4 = v,
|
||||
|
||||
"attr0": (a,v) => a.attr0 = v, "attr1": (a,v) => a.attr1 = v,
|
||||
"attr2": (a,v) => a.attr2 = v, "attr3": (a,v) => a.attr3 = v, "attr4": (a,v) => a.attr4 = v,
|
||||
|
||||
"prop": (a,v) => a.prop = v
|
||||
});
|
||||
}
|
||||
|
|
|
@ -139,6 +139,9 @@ export function setupReflector() {
|
|||
'aatStatusWidth': (o, v) => o.aatStatusWidth = v,
|
||||
'bundles': (o, v) => o.bundles = v,
|
||||
'bundlesWidth': (o, v) => o.bundlesWidth = v,
|
||||
'if': (o, v) => {},
|
||||
'of': (o, v) => {},
|
||||
'cellWidth': (o, v) => o.cellWidth = v,
|
||||
evt: (o, v) => null,
|
||||
'style': (o, m) => {
|
||||
//if (isBlank(m)) return;
|
||||
|
|
|
@ -206,6 +206,7 @@ function setupReflector() {
|
|||
'initData': (a,v) => a.initData = v,
|
||||
'data': (a,v) => a.data = v,
|
||||
'condition': (a,v) => a.condition = v,
|
||||
'if': (a,v) => a['if'] = v,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue