Hello!
I want to access a plugin from my javascript (of course i’m on device, not in browser).
For example, let it be [Ionic Keyboard Plugin for Cordova][1] (i cannot access ANY plugin, not only Keyboard).
I have made everything up to this tutorial Chat tutorial using beta3 (epic).
All i want is to access the plugin from JS code, but with no luck. cordova and window.cordova objects are defined but cordova.plugins seems to be empty.
I have added <script src="cordova.js"></script> to my index.html file.
I have added <feature name="Keyboard"><param name="ios-package" value="IonicKeyboard" onload="true" /></feature> to config.xml.
You should use the plugin after the platform is ready, try using $ionicPlatform.ready() to fire the events just like the initial projects from Ionic.
angular.module( 'starter', ['ionic','starter.controllers','starter.services'] )
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
})
Thanks for response @felipew!
I have tried this solution already but with no result. And I call my function checkPlugins with ng-click (usually much after all other actions like platform ready and so).
I have found that my js code affects cordova plugins loading process somehow. When i use super simple module like @felipew suggested above everything is ok, but when i use the code of my project plugins become broken. So, my new sub-question is how to find the place where my code affects cordova plugins loading?
I guess there is a race condition occurring between controllers being loaded and cordova plugins. I’m having the same issue. I tried bootstrapping the document but was no good to me. Try this solution. Let me know if you found a solution for this.
correct, cordova will not be available in the browser, only on device. In your application code always check to see if the cordova object or the global plugin object is defined before using a plugin so you wont run into issues when developing in a browser.