【发布时间】:2020-11-11 18:39:08
【问题描述】:
当按键按下键盘上的任意键时如何在 mat-input 中聚焦。
试过了:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
【问题讨论】:
标签: angular typescript web angular-cli-v9
当按键按下键盘上的任意键时如何在 mat-input 中聚焦。
试过了:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])
【问题讨论】:
标签: angular typescript web angular-cli-v9
试试这个:
@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();
}
【讨论】: