DEV Community

Facundo Ezequiel Diaz Cappella
Facundo Ezequiel Diaz Cappella

Posted on • Updated on

HostListener how to use

Hi, today I will explain how to use the HostListener decorator easily.

First, this decorator we use for:
This decorator is listening for a specific event by the host element

Go to the code example:
Each time you click inside the component, the counter will increase by 1

  @HostListener("click", ["$event"])
  onClickEvent(event: Event) {
    this.clicksCounts += 1;
  }
Enter fullscreen mode Exit fullscreen mode

If you want to know all the events that you can play with HostListener you can see it in w3school list here ->[https://www.w3schools.com/jsref/dom_obj_event.asp]

Latest comments (0)