Posts

Showing posts with the label hostlistener

HostListener in Angular 17 | Standalone | Listening Events

Image
HostListener   :          This helps us to handle events more easily and one of the best thing about the Hostlistener is we can handle lost of events. Here is an example of how to use @HostListener :             Now we are create a HostListener for listening how many times the user click's our website.  Step - 1 :          We need to create method with functionality for what process we are going to execute when the event triggers.           clickCount = 0 ;    onHostClick ( ) {    this . clickCount ++ ;    } Step - 2 :          Use the @HostListener decorator for listen to the events trigger and we need to pass one argument to this decorator of which event we are listening. Like this           @ HostListener ( 'click' )    onHostClick ( ) { ...