Reputation: 135
I'm trying to import the cordova-plugin-ionic-keyboard like so:
import {Keyboard} from 'cordova-plugin-ionic-keyboard/www/android';
I am trying to use the cordova plugin to prevent the keyboard from closing (and the ionic-plugin-keyboard is deprecated.)
import {Keyboard} from '@ionic-native/keyboard';
export class messages {
constructor (private keyboard:Keyboard){}
sendMessage(){
//send message code
this.keyboard.show()
}
}
How can I correctly import this?
Upvotes: 4
Views: 6684
Reputation: 155
use this.keyboard and no need to import anything. Call this.keyboard.hide()
Upvotes: 0
Reputation: 483
First make sure to get rid of any references to the deprecated ionic-plugin-keyboard as well as @ionic-native/keyboard using this:
ionic cordova plugin remove ionic-plugin-keyboard
npm uninstall --save @ionic-native/keyboard
Check your package.json and your config.xml to be sure all references are gone, in my case I prefer to delete the node_modules and plugins folder when reinstalling plugins, then run
cordova plugin add cordova-plugin-ionic-keyboard --save
To install the non deprecated plugin, now in any class of your project you can use the plugin like this:
import { ViewController, } from 'ionic-angular';
declare var cordova:any;
declare var Keyboard:any;
export class BasePage {
keyboard: any;
constructor(public viewCtrl: ViewController,) {
this.keyboard = Keyboard;
}
You have to always declare the var like this
add declare var Keyboard:any;
after imports.
and use when platform is ready
platform.ready().then(() => {
Keyboard.show();
});
Upvotes: 2