单击按钮时在 Ionic 上保持键盘打开(聊天应用程序)

keep keyboard open on Ionic when button click ( chat app )

我有一个 Ionic v1 聊天应用程序,我做了所有的事情,但是当我点击发送按钮(发送聊天)时我遇到了一个著名的问题,键盘从输入中失去焦点然后关闭。

我尝试了很多方法,但 none 行得通:

非常感谢任何帮助。

<div class="sender">
<input type="text" ng-model="..." class="...">
<div class="button-send">
<span class="send-chat"><i class="ion ion-send"></i></span>
</div>
</div>

尝试通过它的 cordova 插件强制打开键盘 https://github.com/ionic-team/ionic-plugin-keyboard#keyboardshow

好吧,找到了修复方法! 对于那些正在使用 ionic 进行聊天之类的应用程序,并希望键盘在单击按钮后保持专注的所有人,

只需将按钮替换为带有 for="inputID" 的标签,如下所示:

<div class="sender">
<input id="inputID" type="text" ng-model="..." class="...">
<div class="button-send">
<label for="inputID" class="send-chat"><i class="ion ion-send"></i></label>
</div>
</div>

只需使用 (mousedown)="sentMessage(); $event.preventDefault()"

<ion-button (mousedown)="sentMessage(); $event.preventDefault()">
      <ion-icon ios="ios-send" md="md-send"></ion-icon>
</ion-button>
(mousedown)="doSomething(); $event.preventDefault()"

适用于最新的 Ionic 版本。