I am building out an Ionic app in Angular and ave never been able to get plugins to work.
As an example, I have tried using the statusbar plugin as described here:
http://ionicframework.com/tutorials/fullscreen-apps/
But it still shows in my app. I tried:
$ cordova plugin add org.apache.cordova.statusbar
and then "cordova prepare", "ionic run ios" and still no luck.
The plugins I get listed when I type
$ cordova plugin list
com.ionic.keyboard 1.0.2 "Keyboard"
org.apache.cordova.console 0.2.10 "Console"
org.apache.cordova.device 0.2.11 "Device"
org.apache.cordova.statusbar 0.1.7 "StatusBar"
I also am using Gulp. I have a folder with all my dev work in, and gulp moves and compiles it into a /dist folder from whence it is served. I'm pretty sure the plugins are moved across perfectly, is there anywhere I should check the references?
Any ideas if there is something you have to do in order to use Cordova plugins with Ionic?
The answer to this was that I had to add
to my page, just above my scripts.
Please be aware this file doesnt exist during development, it's injected at runtime... which is why I could solve it. Hope this helps someone!
I tested this on Android and iPhone simulator and works correctly. Try this code:
EDIT:
EDIT II: (Try with a fresh Project and iPhone Simulator)
Additional solution if including cordova.js doesn't resolve the problem
I have had the same issue, but
cordova.js
was already included in myindex.html
.window.plugins
always has been undefined. Then I noticed that there is acordova_plugins.js
file inside theplatforms/ios/www
folder.Here's what I did:
$ cordova plugin add cordova-plugin-flashlight
$ cordova prepare
<script src="cordova_plugins.js"></script>
right aftercordova.js
insideindex.html
After that I could access the
window.plugins
variable.HINT: take a look into your
cordova_plugins.js
and be aware that some plugins are attached tocordova.plugins
(e.g. Keyboard Plugin, see below) others are attached towindow.plugins
(e.g. Flashlight)For reference - my cordova_plugins.js file looks like this