Enter事件不会使用angular在Android设备上触发功能

iBu*_*Bug 6 html android cordova angular

有多个问题的答案都与我的问题有关,但不幸的是,没有一个问题对我有用。

我必须检测在android键盘上按下的enter并将焦点从当前的matInput更改为下一个matInput。

我曾尝试keyup.enterkeydownkeypress但没有为我工作。我实现了指令方法,但在Android设备上调试应用程序时未触发方法。虽然,它确实会触发浏览器上的方法。

这是我正在使用的。

HTML:

    <mat-form-field class="ib-input-container-width">
  <input matInput data-dependency="lastName" (keypress)="onChange($event.keyCode)" (keyup.enter)="handleNext('lastName')"  [formControl]="form.get('FirstName')" type="text" >

</mat-form-field>

<mat-form-field class="ib-input-container-width" >
  <input #lastName id="lastName" matInput  [formControl]="form.get('LastName')" type="text">
Run Code Online (Sandbox Code Playgroud)

TS:

  handleNext(elementId){
    let nextElement = document.getElementById(elementId);
    console.log(nextElement);
    nextElement.focus();
  }

  onChange(event){
    console.log(event.keycode);
  }
Run Code Online (Sandbox Code Playgroud)

PS:我正在使用Cordova进行工作的渐进式Web应用程序。

更新资料

我已经尝试过/sf/answers/1967252591/的解决方案, 但是ng-change也不起作用。

小智 2

代码看起来正确,

在 Android 上运行 codova 应用程序之前,请确保您已使用 Angular cli 编译了 Angular 项目,并且输出应设置为 www 文件夹