Ionic 3 : How to use cordova plugins

Whyzx picture Whyzx · Jul 17, 2017 · Viewed 12.1k times · Source

I'm trying to use this cordova plugin https://github.com/litehelpers/Cordova-sqlcipher-adapter.

Here my code :

...
import { Platform } from 'ionic-angular';

declare var cordova;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(platform: Platform) {
    platform.ready().then(() => {
      alert(cordova.plugins.sqlitePlugin);
    });
  }

The problem is, what-ever I do, sqlitePlugin is always undefined :/ However cordova.plugins is an object.

I also tried alert((<any>window).plugins.sqlitePlugin); but the result is the same.

I'm running in an Nexus 5X Android 8 device.

I have installed the plugin this way : ionic cordova plugin add cordova-sqlcipher-adapter --save as a standard cordova plugin.

Any helps would be appreciate :)

Answer

Whyzx picture Whyzx · Jul 17, 2017

After several hours, the correct way to use the plugin was : (<any>window).sqlitePlugin

Hope it could helps :)