DEV Community

Facundo Ezequiel Diaz Cappella
Facundo Ezequiel Diaz Cappella

Posted on • Edited on

3 3

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]

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay