【问题标题】:Angular 9: how to focus in mat-input when key press anykeyAngular 9:按键按下任意键时如何专注于垫子输入
【发布时间】:2020-11-11 18:39:08
【问题描述】:

当按键按下键盘上的任意键时如何在 mat-input 中聚焦。

试过了:

@HostListener('document:keydown', ['this.search.nativeElement.focus()'])

【问题讨论】:

    标签: angular typescript web angular-cli-v9


    【解决方案1】:

    试试这个:

    @HostListener('document:keypress', ['$event'])
        handleKeyboardEvent(event: KeyboardEvent) {
            this.search.nativeElement.focus();
        }
    

    【讨论】:

      【解决方案2】:

      YAY 已修复,谢谢

       @HostListener('document:keypress', ['$event'])
        handleKeyboardEvent(event: KeyboardEvent) {
          this.search.nativeElement.focus();
          this.searchFocus();
        }
      
        keyboardFocusOut() : void {
          this.searchText = ""
          this.search.nativeElement.blur();
          this.searchFocusOut();
        }
      

      【讨论】:

        猜你喜欢
        • 2021-07-30
        • 2018-01-14
        • 2014-05-06
        • 2016-03-06
        • 1970-01-01
        • 2011-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多