Enter事件不会使用angular在Android设备上触发功能 [英] Enter event doesn't trigger the function on Android device using angular

查看:84
本文介绍了Enter事件不会使用angular在Android设备上触发功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存在多个与我的问题相关的答案的问题,但不幸的是,没有一个问题对我有用.

There are multiple questions with answers related to my problem but unfortunately, none worked for me.

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

I have to detect the enter pressed on android keyboard and change focus from current matInput to next matInput.

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

I have tried keyup.enter, keydown and keypress but none worked for me. I implemented directive approach but doesn't trigger method when I am debugging app on Android device. Although, it does trigger the method on browser.

这是我正在使用的.

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">

TS:

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

  onChange(event){
    console.log(event.keycode);
  }

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

PS: I am on a working progressive web app using Cordova.

更新

我尝试了 https://stackoverflow.com/a/28103608/3081929 的解决方案 但是ng-change也不起作用.

I have tried solution from https://stackoverflow.com/a/28103608/3081929 But ng-change doesn't work either.

推荐答案

代码看起来正确,

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

before running your codova app on android make sure you have compiled the angular project using angular cli and output should be set to www folder

这篇关于Enter事件不会使用angular在Android设备上触发功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆