//method 1
<input (keyup)="onKey($event)">
Email: <p>{{email}}</p>
//ts
export class AppComponent {
email: String = '';
onKey(event: KeyboardEvent) {
this.email = event.target['value'];
console.log("event", event);
}
}
//method 2
<input (keyup)="onKey($event)" (keypress)="onKey($event)" (keydown)="onKey($event)" >
export class AppComponent {
onKey(event: KeyboardEvent) {
console.log("This is", event.type);
}
}
//method 3
@HostListener("window:keypress", ["$event"])
handleKeyboardEvent(event: KeyboardEvent) {
console.log(event);
}