离子2 - 单击发送按钮时保持键盘打开

时间:2017-05-03 19:57:03

标签: angular keyboard ionic2 focus textarea

当输入/ textarea字段聚焦(?)时,离子键盘会打开。

但是当我点击发送按钮时,键盘会消失。

即使我调用键盘插件的keyboard.show()方法,它也会先消失,然后重新出现。

有解决方法吗?

<textarea id="chat-text-area></textarea>

sendMessage() {
    if(window.cordova){
        this.keyboard.show()
    }
    if(this.form.valid){
        this.service.post(this.form.value).subscribe(res=>{
            document.getElementById('chat-text-area').focus()
        })
    }
}

2 个答案:

答案 0 :(得分:3)

将此添加到您的发送按钮:

(mousedown)="$event.preventDefault(); sendMessage($event)"

我希望有帮助:)

答案 1 :(得分:1)

你能在hide事件中注入你的逻辑吗?

window.addEventListener('native.keyboardhide', keyboardHideHandler);

function keyboardHideHandler(e){
    if (something) // put your condition here
        e.preventDefault();
}
相关问题