如何在键盘上按任意键的情况下,在mat输入中聚焦。
已经尝试过:
@HostListener('document:keydown', ['this.search.nativeElement.focus()'])发布于 2020-07-22 17:03:53
试试这个:
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
}发布于 2020-07-22 21:57:29
耶,修好了,谢谢
@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
this.search.nativeElement.focus();
this.searchFocus();
}
keyboardFocusOut() : void {
this.searchText = ""
this.search.nativeElement.blur();
this.searchFocusOut();
}https://stackoverflow.com/questions/63030498
复制相似问题