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.
Loading...
Related Quiz
- What's the purpose of the FormBuilder service in Angular's reactive forms?
- The NG_VALUE_ACCESSOR token is used to provide the ________ for a custom form control.
- When creating a custom attribute directive, which decorator is used to define its metadata?
- Which of the following is NOT a valid RxJS operator commonly used in Angular?
- In NgRx, what would you use to handle side effects like API calls?