0
我正在開發與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上模擬我的代碼並單擊textarea時,鍵盤顯示:perfect。
唯一的問題是,當我點擊發送按鈕,鍵盤隱藏但onSend()函數沒有執行,我必須再次點擊它。
我怎樣才能設法只點擊一次,這一次點擊都會隱藏鍵盤並執行我的onSend()代碼?