parent
709a6dea06
commit
13ecc140e8
|
@ -71,6 +71,13 @@ export class DirectiveResolver {
|
||||||
} else if (a instanceof HostBinding) {
|
} else if (a instanceof HostBinding) {
|
||||||
const hostBinding: HostBinding = a;
|
const hostBinding: HostBinding = a;
|
||||||
if (hostBinding.hostPropertyName) {
|
if (hostBinding.hostPropertyName) {
|
||||||
|
const startWith = hostBinding.hostPropertyName[0];
|
||||||
|
if (startWith === '(') {
|
||||||
|
throw new Error(`@HostBinding can not bind to events. Use @HostListener instead.`);
|
||||||
|
} else if (startWith === '[') {
|
||||||
|
throw new Error(
|
||||||
|
`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
|
||||||
|
}
|
||||||
host[`[${hostBinding.hostPropertyName}]`] = propName;
|
host[`[${hostBinding.hostPropertyName}]`] = propName;
|
||||||
} else {
|
} else {
|
||||||
host[`[${propName}]`] = propName;
|
host[`[${propName}]`] = propName;
|
||||||
|
|
|
@ -117,6 +117,18 @@ class SomeDirectiveWithSameHostBindingAndInput {
|
||||||
@Input() @HostBinding() prop: any;
|
@Input() @HostBinding() prop: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Directive({selector: 'someDirective'})
|
||||||
|
class SomeDirectiveWithMalformedHostBinding1 {
|
||||||
|
@HostBinding('(a)')
|
||||||
|
onA() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Directive({selector: 'someDirective'})
|
||||||
|
class SomeDirectiveWithMalformedHostBinding2 {
|
||||||
|
@HostBinding('[a]')
|
||||||
|
onA() {}
|
||||||
|
}
|
||||||
|
|
||||||
class SomeDirectiveWithoutMetadata {}
|
class SomeDirectiveWithoutMetadata {}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
|
@ -210,6 +222,17 @@ export function main() {
|
||||||
expect(directiveMetadata.host)
|
expect(directiveMetadata.host)
|
||||||
.toEqual({'(c)': 'onC()', '(a)': 'onA()', '(b)': 'onB($event.value)'});
|
.toEqual({'(c)': 'onC()', '(a)': 'onA()', '(b)': 'onB($event.value)'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw when @HostBinding name starts with "("', () => {
|
||||||
|
expect(() => resolver.resolve(SomeDirectiveWithMalformedHostBinding1))
|
||||||
|
.toThrowError('@HostBinding can not bind to events. Use @HostListener instead.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw when @HostBinding name starts with "["', () => {
|
||||||
|
expect(() => resolver.resolve(SomeDirectiveWithMalformedHostBinding2))
|
||||||
|
.toThrowError(
|
||||||
|
`@HostBinding parameter should be a property name, 'class.<name>', or 'attr.<name>'.`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('queries', () => {
|
describe('queries', () => {
|
||||||
|
|
Loading…
Reference in New Issue