Hello,
How to integrate cordova plugins for example appnext-plugin and how to use the functionalities of the plugin in ionic please help me
You must first add plugin to project. Find the plugin at http://ionicframework.com/docs/native/ url. If plugin doesn’t exist, you must follow different approach.
- Add cordova plugin:
cordova plugin add xxx
- Declare any in component.ts file.
declare let cordova: any;
- Use javascript functions.
ngOnInit(){
cordova.xxx.
}
Code:
import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
declare let cordova: any;
@Component({
selector: 'page-contact',
templateUrl: 'contact.html'
})
export class ContactPage implements OnInit {
constructor(public navCtrl: NavController) {
}
ngOnInit(){
cordova.xxx.
}
}
oh thanks let me try that
I tried declare var cordova:any; but it doesnt work for me is there any alternative
You’ll need to access the plugin’s functionality through the plugins
namespace on window
object like this:
(<any>window).plugins.pluginName.pluginMethod();
This is my preferred way to use it. If you don’t want to use < any> everytime, you can first use this line above the @Component decorator:
declare var window;
and then use
window.plugins.pluginName.pluginMethod();
UPDATE: If the above line does not work, please try window.pluginName.pluginMethod()
For further insights, you can refer to the last topic “Using a Plugin Not Included in Ionic Native” on Using non-ionic-native plugins in ionic 2+ blog by joshmorony. Hope this solves your problem. Please reach our for any further assistance. Cheers!