单击离子页脚中的按钮起初不执行(单击)功能



我正在开发与Ionic 2的聊天。我使用了键盘附加指令。

//View
    <ion-footer [keyboardAttach]="content">
      <ion-toolbar class="text_send">
        <ion-textarea class="textarea" fz-elastic placeholder="Message" [(ngModel)]="message"></ion-textarea>
        <button ion-button small icon-only round color="secondary" (click)="onSend()">
          <ion-icon name="send"></ion-icon>
        </button>
      </ion-toolbar>
    </ion-footer>
// Controller
onSend() {
    console.log('Send new message ', this.message);
    if (this.id === 'new') {
      this.messageService.createChatAndSendFirstMessage(this.cuid, this.recipientUid, this.message)
      .then(newChatId => {
        // Get last messages of the new chat so that it gets displayed in the view
        this.messages$ = this.messageService.getLastMessages(newChatId, this.ccompany, 20);
        // Update chat id in case the user send more than 1 message
        // In this case it should be the regular behavior for non new messages
        this.id = newChatId;
      })
      .catch(error => console.log('ChatPage#onSend - Error while sending new message ', error));
    } else {
      // If a chat already exists with this user
      this.messageService.sendMessage(this.id, this.cuid, this.recipientUid, this.message)
      .catch(error => console.log('ChatPage#onSend - Error while sending new message ', error));
    }
    // Empty the message input
    this.message = '';
  }

当我在iOS上模拟我的代码并单击文本区域时,键盘显示:完美。

唯一的问题是,当我单击发送按钮时,键盘会隐藏,但 onSend(( 函数没有执行,我必须第二次单击它。

我怎么能设法只单击一次,而这一次单击将同时隐藏键盘并执行我的 onSend(( 代码?

我在应用程序的各个部分使用键盘附加指令做同样的事情,没有问题。我相信这可能是由您使用的(点击(发射器引起的。

尝试将其更改为(点击(

我相信在ios safari中使用(单击(存在一些已知问题。 离子2点击与点击

最新更新