With the following command I installed a cordova plugin on my ionic2 project:
cordova plugin add cordova-plugin-rfduino
This plugin is not available in the Ionic Native. How can I use the plugin in an ionic page? Can I export it somehow?
With the following command I installed a cordova plugin on my ionic2 project:
cordova plugin add cordova-plugin-rfduino
This plugin is not available in the Ionic Native. How can I use the plugin in an ionic page? Can I export it somehow?
When you install the plugin you can use it from the global window
object, but the typescript will not understand what is rfduino
object and its type, so you have to declare it to the declarations file which is located in src/declarations.d.ts
, so you will be able to use it by just adding this line of code in that file
declare var rfduino: any;
I fixed it the following way:
0 - Install your plugin
1- npm install typings --global
2 - On typings/index.d.ts put the following code:
interface Window {
plugins: any;
}
3 - Then use the window the following way inside the page or component:
constructor(platform: Platform) {
platform.ready().then(() => {
var blabla = window['cordova_plugin_that_was_installed'].function();
});
}}