angular: HostBinding can't bind to host input property other than `class.`, `attr.` and `style.`

I’m submitting a … (check one with “x”)

[x ] bug report

Current behavior When binding to a custom input property acproperty on the host component using @HostBinding() I get an error:

Can’t bind to ‘acproperty’ since it isn’t a known property of ‘a-comp’

Expected behavior I expect @HostBinding() decorator to bind to any property on the host component, not just the ones with class., attr. and style.

Minimal reproduction of the problem with instructions Here is the Plunker

Windows10, Angular 4.x, Chrome

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 35 (23 by maintainers)

Most upvoted comments

And also opposite as:

@Directive({
  selector: '[some-directive]'
})
export class SomeDirective {
  constructor(private _someComponent: SomeComponent)
}

You may say that ^^ is not for general using because of specific typing. You are right. But there is a solution using:

constructor(@Optional() private _parent: Parent) {

where Parent is defined on any component as:

@Component({
   providers: [{ provide: Parent, useExisting: forwardRef(() => AnyComponent) }]
})
export class AnyComponent implements Parent {
   name = 'AnyComponent';
}

where Parent is abstract class:

export abstract class Parent {
   name: string;
}

@maximusk Just use the normal DI way in constructor as if it’s a service, an example can be found in: http://plnkr.co/edit/BxCmIX1Ghkx39WgdzJAv?p=preview