I need to capture keypress/keydown/keyup on any element. I did use a directive to handle it. So I defined a KeyPressedDirective :
import { Directive, ElementRef } from '@angular/core'; @Directive({ selector: '[appKeyPressed]' }) export class KeyPressedDirective { constructor(elRef:ElementRef<HTMLElement>) { elRef.nativeElement.addEventListener('keypress',e=>console.log(e)); } } but by using the directive nothing happen and event did not capture.
<p appKeyPressed>Capture keypoard events</p> How should I capture keyboard events?
Here is a StackBlits link: KeyPressDirective
keypress/keydown/keyup, These events will work on input element. Please try