Is there any way to hide keyboard when focusing an ion-input?

感情迁移 提交于 2020-08-07 08:13:32

问题


I wanted to have an ion-input that will be focused and the keyboard should not appear. Is there any way or is it possible? Thank you!


回答1:


yes, install this plugin -> https://ionicframework.com/docs/native/keyboard/

html

<ion-input type="text" [(ngModel)]="message"  (ionFocus)="keyboard_show()"  #input ></ion-input>

ts

    import {
      Keyboard
    } from '@ionic-native/keyboard';

    constructor(private keyboard: Keyboard, private ) {
    }
      keyboard_show(){
       this.keyboard.close();
      }



回答2:


I tried Kevin's answer and got the same 'Keyboard' refers to a value, but is being used as a type here. Did you mean 'typeof Keyboard'? issue that Mitesh got.

I resolved this with:

import { Keyboard } from '@ionic-native/keyboard/ngx'

@Component({
  selector: 'app-upload-root',
  templateUrl: 'upload-root.page.html',
  styleUrls: ['upload-root.page.scss'],
  providers: [Keyboard]
})

constructor(private keyboard: Keyboard)

this.keyboard.hide();

Not sure how or why this was needed, but it works for me.



来源:https://stackoverflow.com/questions/51926420/is-there-any-way-to-hide-keyboard-when-focusing-an-ion-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!