I'm new to Ionic and Cordova. I need to create a plugin for ionic using Cordova and integrate it in sample ionic app.
Steps I Followed are:
Created a simple ionic plugin using plugman
plugman create --name SayHello --plugin_id cordova-plugin-sayhello -plugin_version 0.0.1
Added android platform to above plugin.
cd SayHello/ && plugman platform add --platform_name android
Now I want to integrate this plugin into my ionic app.
ionic cordova plugin add ../SayHello
In my ionic app inside Home.ts, I wrote this piece of code.
declare var cordova: any;
var success = function(result) {
console.log(result);
}
var failure = function(err) {
console.log(err);
}
cordova.plugins.HelloWorld.coolMethod("SayHelloTest", success, failure);
The problem is I cannot call any function from success or failure in the ionic app.
like if I call function doSomething from success:
var success = function(result) {
doSomething(result);
}
It Shows Error doSomething function not found. It can only print in console.
you need to create success as the class function and either send it as a bound function or call inside arrow.