@HostBinding and @HostListener: what do they do and what are they for?

前端 未结 7 934
[愿得一人]
[愿得一人] 2020-11-30 16:57

In my meanderings around the world wide interweb, and now especially the angular.io style docs, I find many references to @HostBinding and @HostListener

7条回答
  •  执笔经年
    2020-11-30 17:56

    A quick tip that helps me remember what they do -

    HostBinding('value') myValue; is exactly the same as [value]="myValue"

    And

    HostListener('click') myClick(){ } is exactly the same as (click)="myClick()"


    HostBinding and HostListener are written in directives and the other ones (...) and [..] are written inside templates (of components).

提交回复
热议问题