Ionic 3 Cordova plugin gives undefined error


#1

Hi

I added a Cordova plugin from GitHub, which is not part of the ionic-native plugins. The plugin does show under the list of plugins when I run cordova plugin list, so it has been added successfully, but when I call a method from the plugin, I get this error:

ReferenceError: CustomPlugin is not defined

Here is my code:

import { Component, OnInit } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;

declare var CustomPlugin: any;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage implements OnInit {

constructor(public navCtrl: NavController) { }

ngOnInit() {

CustomPlugin.initialise(function () {

  CustomPlugin.setReceiveScanCallback(function (data, type) {
    console.log("scan received: " + data + "(" + type + ")");
  });

});

}

scanBarcode() {

CustomPlugin.requestScan(function () { });

}
}


#2

Hello,

post what plugin you use. Maybe someone has solved this in the past.

The error says that your declare var CustomPlugin: any; is not working properly.
That problem could be, that plugin paths could be declared different. Look here How to use non native plugins on Ionic?

Best regards, anna-liebt


#3

Hi @anna_liebt

Thanks for the reply.

I tested another plugin and it worked, so I believe this plugin works a it different than the normal way of declaring plugins.


#4

Hello,
again. Post name or link to plugin. Maybe some could give you a much better advice.

Best regards, anna-liebt


#5

Hi @anna_liebt,

Sorry, my bad.
I am referring to this plugin: https://github.com/mribbons/cordova-plugin-cipherlab-rs30

Kind Regards