I have a component called ListComponent and I have the following code in it.
@HostListener("document:keydown", ["$event"])
handleKeyEvent(event: KeyboardEvent) {
switch(event.keyCode) {
case 38: //up arrow
this.selectPreviousItem();
break;
case 40: //down arrow
this.selectNextItem();
break;
}
}
When I press up arrow or down arrow key, event fires for all instances of the component on a page. How can I fire the event only for the focused element?