Installing ngCordova Install using Bower

You can install ngCordova using Bower.


bower install ngCordova

Note: Bower must be installed before you run the above command.

 

Installing through Source File

Alternatively, you can download the ngCordova using.


https://github.com/driftyco/ng-cordova/archive/master.zip

Include ng-cordova.js or ng-cordova.min.js in your index.html file before cordova.js.


<script src="lib/ngCordova/dist/ng-cordova.js"></script>

<script src="cordova.js"></script>

 

Inject ngCordova to AngularJS

You must include the ngCordova service in app.js file, which resides inside www/js folder.


angular.module('starter', ['ionic','ngCordova'])

 

deviceready event - important !

Before using the plugin, you must check if all the library files are loaded. Like document.ready function in jquery, we have deviceready or ionicplatform.ready.

Therefore, you must use deviceready before using the plugin.


document.addEventListener("deviceready", function () {

$cordovaPlugin.someFunction().then(success, error);}, false);

// OR with IONIC

$ionicPlatform.ready(function() {

$cordovaPlugin.someFunction().then(success, error);});

 

Add ngCordova Plugin to Project

To add ngCordova plugin to your project, execute the below command.


cordova plugin add plugin-name

 

The correct way to add ngCordova plugin

Create an Ionic project.


ionic start appname blank

Then go to project folder.


cd appname

Then add ngCordova plugin to your project using.


cordova plugin add plugin-name