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