I would like to call some method, when ESCape button will be pressed. I did it in this way:
@HostListener('window:keydown', ['$event'])
clickEscape(event: KeyboardEvent) {
//if ESC was pressed
if(event.keyCode === 27) {
this.someMethod();
}
}
But clickEscape method will be called every time, when user click any button on keybord. And my question is:
Is it possible to set HostListener so that method will be called only when detect ESCape button? I was thinking about something in style:
@HostListener('window:keydown["ESCAPE"]')
someMethod() {
//...
}
Is there similar event?
You can indeed use keydown.escape:
@HostListener('window:keydown.escape')
someMethod() {
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With