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