Skip to content

Commit 2768158

Browse files
pkozlowski-opensourcetbosch
authored andcommitted
tests(ProtoViewBuilder): host properties binding to unknown props
When binding a host property, we shouldn't try to bind to any directive properties that might exist on a host element Closes angular#3383
1 parent f8fa47e commit 2768158

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

modules/angular2/src/render/dom/view/proto_view_builder.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class ProtoViewBuilder {
9393
propertyBindings: dbb.propertyBindings,
9494
eventBindings: dbb.eventBindings,
9595
hostPropertyBindings: buildElementPropertyBindings(schemaRegistry, ebb.element, true,
96-
dbb.hostPropertyBindings, new Set())
96+
dbb.hostPropertyBindings, null)
9797
});
9898
});
9999
var nestedProtoView =
@@ -336,9 +336,15 @@ function buildElementPropertyBindings(
336336
if (isValidElementPropertyBinding(schemaRegistry, protoElement, isNgComponent,
337337
propertyBinding)) {
338338
propertyBindings.push(propertyBinding);
339-
} else if (!SetWrapper.has(directiveTempaltePropertyNames, propertyNameInTemplate)) {
340-
throw new BaseException(
341-
`Can't bind to '${propertyNameInTemplate}' since it isn't a known property of the '<${DOM.tagName(protoElement).toLowerCase()}>' element and there are no matching directives with a corresponding property`);
339+
} else if (!isPresent(directiveTempaltePropertyNames) ||
340+
!SetWrapper.has(directiveTempaltePropertyNames, propertyNameInTemplate)) {
341+
// directiveTempaltePropertyNames is null for host property bindings
342+
var exMsg =
343+
`Can't bind to '${propertyNameInTemplate}' since it isn't a known property of the '<${DOM.tagName(protoElement).toLowerCase()}>' element`;
344+
if (isPresent(directiveTempaltePropertyNames)) {
345+
exMsg += ' and there are no matching directives with a corresponding property';
346+
}
347+
throw new BaseException(exMsg);
342348
}
343349
});
344350
return propertyBindings;

modules/angular2/test/render/dom/view/proto_view_builder_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export function main() {
4444
expect(() => builder.build(new DomElementSchemaRegistry())).not.toThrow();
4545
});
4646

47+
it('should throw for unknown host properties even if another directive uses it', () => {
48+
var binder = builder.bindElement(el('<div/>'));
49+
binder.bindDirective(0).bindProperty('someDirProperty', emptyExpr(), 'someDirProperty');
50+
binder.bindDirective(1).bindHostProperty('someDirProperty', emptyExpr());
51+
expect(() => builder.build(new DomElementSchemaRegistry()))
52+
.toThrowError(
53+
`Can't bind to 'someDirProperty' since it isn't a known property of the '<div>' element`);
54+
});
55+
4756
it('should allow unknown properties on custom elements', () => {
4857
var binder = builder.bindElement(el('<some-custom/>'));
4958
binder.bindProperty('unknownProperty', emptyExpr());

0 commit comments

Comments
 (0)