1.

What are Method decorators?

Answer»

Method decorators, as the name implies, are used to add functionality to the methods defined within our class.

Example: @HostListener, is a good example of method decorators.

import { Component, HostListener } from '@angular/core'; 
@Component({ 
selector: 'method-component', 
template: '<div> This is a test method component ! </div>', 
}) 
export class MethodComponent { 
 @HostListener('click', ['$event'])
   onHostClick(event: Event) {
   console.log('clicked now this event is available !'); 
   }
}

The @HostListener decorator is used before the onHostClick () method in the above example code.




Discussion

No Comment Found