1

我正在与 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() 代码?

4

1 回答 1

2

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

尝试将其更改为(点击)

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

于 2017-06-13T13:53:20.443 回答