Ionic 3: How to use cordova plugins

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

Here is 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 that whatever I do is sqlitePlugin

always undefined

: / However cordova.plugins

is an object.

I have also tried alert((<any>window).plugins.sqlitePlugin);

but the result is the same.

I am working on a Nexus 5X Android 8 device.

I installed the plugin like this: ionic cordova plugin add cordova-sqlcipher-adapter --save

as a standard cordova plugin.

Any help would be appreciated :)

+10


source to share


4 answers


After a few hours the correct way to use the plugin is: (<any>window).sqlitePlugin



Hope this can help :)

+18


source


You can also write it as



window["pluginName"]

      

+1


source


For my case, I am using

 (<any>window)["plugins"].plugin

      

It works.

0


source


This works for me

window["pluginName"].pluginFunction

      

0


source







All Articles