It's my first time doing this.
I have @Hostlistener in app.component to listen for 'ESC'. (acts like a global listener)
@HostListener('document:keydown', ['$event'])
public onKeydownHandler(event: KeyboardEvent): void {
....... // listens for 'ESC'
}
and I have another @Hostlistener in input.component (listen for 'ENTER' in input fields)
@HostListener('keydown', ['$event'])
public onKeydownHandler(event: KeyboardEvent): void {
....... // listens for 'ENTER'
}
What happens now is when I am not in the input fields, 'ESC' will be detected. When I am in the input fields, 'ESC' will not be detected.
Expected behavior: 'ESC' should be detected even inside the input fields.
It seems like the global listener doesn't work like I expected. Is this the correct behavior?