单击离子页脚内的按钮首先不执行(单击)功能

时间:2017-06-13 13:19:57

标签: angular ionic2 ionic-keyboard

我正在与Ionic 2进行聊天。我使用了keyboard-attach指令。

//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上模拟我的代码并单击textarea时,键盘显示:perfect。

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

我怎么能设法只点击一次,这一次点击都会隐藏键盘并执行我的onSend()代码?

1 个答案:

答案 0 :(得分:2)

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

尝试将其更改为(点按)

我相信在ios safari中使用(点击)存在一些已知问题。 ionic2 tap vs click