How can you create a directive that listens for host events and reacts accordingly?

  • Define an event listener function inside the component class.
  • Implement the OnHostEvent interface.
  • Use the @DirectiveEvent decorator.
  • Use the @HostListener decorator.
To create a directive that listens for host events and reacts accordingly, you should use the @HostListener decorator. This decorator allows you to define event listeners directly within the directive class, making it easy to respond to events on the host element where the directive is applied.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *