在Ionic Chat应用程序的聊天页面中发送消息后,我想始终打开我的移动键盘。因为在单击发送按钮时,第一次单击时,键盘会关闭,然后,在第二次单击时,消息会被发送。因此,在Ionic 3应用程序中,它需要时间并显示出滞后。
有没有办法解决离子应用(离子3/4)中的键盘问题?
发布于 2020-02-12 14:20:13
preventDefault() and stopPropagation()是帮助保持键盘打开的主要概念。为了完成此功能,我在聊天页面的Send Button中添加了#sendButton。并使用ViewChild,
@ViewChild('sendButton') private sendButton:Button;然后,我将以下代码添加到我的.ts页面。并在ngOnInit()上调用此函数(也可以使用ionViewDidLoad()或ionViewWillLoad())
keepKeyboardVisible() {
if(!!this.sendButton){
let el = this.sendButton._elementRef.nativeElement;
console.log(el);
el.addEventListener('click', (event) => {
this.stopBubble(event);
});
el.addEventListener('touchdown', (event) => {
this.stopBubble(event);
});
el.addEventListener('touchmove', (event) => {
this.stopBubble(event);
});
el.addEventListener('touchstart', (event) => {
this.stopBubble(event);
});
el.addEventListener('touchend', (event) => { //Triggered by a phone
this.stopBubble(event);
this.sendMessage();
});
}
}
stopBubble(event) {
console.log(event);
event.preventDefault();
event.stopPropagation(); //Stops event bubbling
}https://stackoverflow.com/questions/59520735
复制相似问题