按下键盘上的任意键时如何在 mat-input 中聚焦。
试过:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
按下键盘上的任意键时如何在 mat-input 中聚焦。
试过:
@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();
}