How to focus in mat-input when key press any key on keyboard.
have tried:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
How to focus in mat-input when key press any key on keyboard.
have tried:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
Try this:
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
}
YAY Fixed it and Thank you
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
this.searchFocus();
}
keyboardFocusOut() : void {
this.searchText = ""
this.search.nativeElement.blur();
this.searchFocusOut();
}