Angular 9: 键盘按下任意键时如何在mat-input中聚焦
Angular 9: how to focus in mat-input when key press anykey
如何在按下键盘上的任意键时在垫输入中聚焦。
尝试过:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
试试这个:
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
}
YAY 修复了它,谢谢
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
this.searchFocus();
}
keyboardFocusOut() : void {
this.searchText = ""
this.search.nativeElement.blur();
this.searchFocusOut();
}
如何在按下键盘上的任意键时在垫输入中聚焦。
尝试过:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
试试这个:
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
}
YAY 修复了它,谢谢
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
this.searchFocus();
}
keyboardFocusOut() : void {
this.searchText = ""
this.search.nativeElement.blur();
this.searchFocusOut();
}