【问题标题】:Event native keyboardshow not firing in Ionic 3事件本机键盘显示未在 Ionic 3 中触发
【发布时间】:2018-06-08 06:32:34
【问题描述】:

我在 Ionic 3 中有一个应用程序,我想使用事件 native.keyboardshow 来隐藏键盘,但该事件从未被触发。我在生命钩子 onInit 中声明事件,如下所示:

ngOninit() {    
  window.addEventListener('native.keyboardshow', function(){
    document.body.classList.add('keyboard-open');
    alert('just to check if it's working in mobile);
  });
}

任何想法为什么事件不起作用? 谢谢!

【问题讨论】:

    标签: angular typescript ionic-framework mobile ionic3


    【解决方案1】:

    安装 Cordova 和 Ionic Native 插件:

    $ ionic cordova plugin add ionic-plugin-keyboard
    $ npm install --save @ionic-native/keyboard
    

    用法

    import { Keyboard } from '@ionic-native/keyboard';
    
    constructor(private keyboard: Keyboard) { }
    
    ...
    
    this.keyboard.show();
    
    this.keyboard.close();
    

    来源: https://ionicframework.com/docs/native/keyboard/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      • 2016-08-30
      • 2015-11-17
      • 2011-03-06
      • 2013-09-22
      • 1970-01-01
      • 2012-09-09
      相关资源
      最近更新 更多