host listener click event code example
Example: host listener click event
content_copy
@Directive({selector: 'button[counting]'})
class CountClicks {
numberOfClicks = 0;
@HostListener('click', ['$event.target'])
onClick(btn) {
console.log('button', btn, 'number of clicks:', this.numberOfClicks++);
}
}
@Component({
selector: 'app',
template: '<button counting>Increment</button>',
})
class App {}