【问题标题】:Is there any way to hide keyboard when focusing an ion-input?聚焦离子输入时有什么方法可以隐藏键盘吗?
【发布时间】:2018-08-20 08:02:22
【问题描述】:

我想要一个离子输入,它会被聚焦并且不应该出现键盘。有什么办法或者有可能吗?谢谢!

【问题讨论】:

    标签: ionic-framework ionic3 setfocus ionic-keyboard


    【解决方案1】:

    是的,安装这个插件 -> 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();
          }
    

    【讨论】:

    • 函数keyboard_show()应该在构造函数里面吗?
    • 把它放在构造函数之外
    • 它给出错误:'Keyboard' refers to a value, but is being used as a type here. Did you mean 'typeof Keyboard'?
    【解决方案2】:

    我尝试了 Kevin 的回答,得到了与 Mitesh 相同的 'Keyboard' refers to a value, but is being used as a type here. Did you mean 'typeof Keyboard'? 问题。

    我解决了这个问题:

    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();
    

    不确定如何或为什么需要这样做,但它对我有用。

    【讨论】:

    • 75% 的情况下遇到此错误,将 ngx 添加到 import 语句可以解决问题。
    猜你喜欢
    • 2017-02-12
    • 1970-01-01
    • 2017-11-07
    • 2015-09-03
    • 1970-01-01
    • 2018-11-02
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多