0 votes
in Angular by
What are Method decorators in Angular?

1 Answer

0 votes
by

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.

...