How to use @HostBinding with @Input properties in Angular 2?

前端 未结 5 1662
青春惊慌失措
青春惊慌失措 2020-12-29 20:27

(Angular 2 RC4)

With @HostBinding we should be able to modify properties of the host, right? My question is, does this apply to @Input() properties as well and if so

5条回答
  •  清酒与你
    2020-12-29 21:03

    @HostBinding() doesn't create property bindings to properties of the host component. That might be worth a bug report though ;-)

    I got it working by a workaround with exportAs and a template variable but that is quite ugly. https://plnkr.co/edit/TobNVn?p=preview

    After some consideration, I think it should work. Otherwise I wouldn't know what @HostBinding() src; would do at all.

    @HostBinding('attr.src') src; or @HostBinding('class.src') src; are the more common cases.

提交回复
热议问题