ngCordova
In the earlier example, we have integrated a couple of plugins and used their JavaScript API methods to interact with them. As you may have noticed, all the plugins reside in the global namespace. Unlike AngularJS's philosophy of dependency injection, Cordova's plugins reside in the global namespace and can be accessed from anywhere. This might be a problem when you are testing your application, built with the concept of dependency injection.
So, the Ionic team came up with a wrapper around the Cordova plugins, whereby you can inject the features as services. In the preceding example, instead of using device.model
, we will inject a dependency named $cordovaDevice
, and then access properties using the $cordovaDevice.getModel
method.
The ngCordova library is not specific to Ionic; this can be used in conjunction with any Cordova app built using AngularJS.
The ngCordova library has 71 plugins at the time of writing this chapter.
For now, let's test-drive a few ngCordova plugins.