Working with non ionic-native plugins in Ionic 2

I’m using a custom cordova plugin (https://github.com/VJAI/simple-crypto), not available in ionic native.

I’m using Ionic 2 and have installed the plugin using the command:
cordova plugin add https://github.com/VJAI/simple-crypto

The interface is like this:

var rncryptor = cordova.require("com.disusered.simplecrypto.SimpleCrypto");

rncryptor.encrypt(key, data, successCallback, failureCallback)
rncryptor.decrypt(key, data, successCallback, failureCallback)`

Method 1:
I have tried to invoke the plugin using

window.plugins.SimpleCrypto.encrypt(...)

But when I run ionic serve, i get the error:

TypeError: Cannot read property ‘SimpleCrypto’ of undefined

Method 2:
Another way i tried was

cordova.plugins.SimpleCrypto.encrypt(...)

The error i got was

ReferenceError: cordova is not defined

Is there any way to go around doing this?

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Have you tried to use

cordova.plugins.SimpleCrypto.encrypt 

function on your device?

It is working for my case. The reason being, the emulator is unable to run cordova.js

Jason
Guest

You could try…

declare var SimpleCrypto:any;

SimpleCrypto.encrypt(...)