Ishan Mihir
Ishan Mihir

Reputation: 83

How to include ngCordova plugins in my ionic app?

I want to add Cordova plugins into my ionic app. But it seems that it isn't working.

I will walk you through the steps I took:

  1. Added cordova plugins in the plugins folder.
  2. Included ng-cordova.min.js file in index.html before codova.js
  3. Injected ngCordova in app.js
  4. Injected the required plugin in my controller ( $cordovaBarcodeScanner in this case)

Can someone please help me with that?

Upvotes: 3

Views: 3202

Answers (2)

Carlo Bonamico
Carlo Bonamico

Reputation: 153

You can add the plugin with

cordova plugin add https://github.com/wildabeast/BarcodeScanner.git

then use the plugin in your page like this

module.controller('BarcodeCtrl', function($scope, $cordovaBarcodeScanner) {
document.addEventListener("deviceready", function () {

  $cordovaBarcodeScanner
    .scan()
    .then(function(barcodeData) {
      // Success! Barcode data is here
    }, function(error) {
      // An error occurred
    });
)};

This example and more information are available at http://ngcordova.com/docs/plugins/barcodeScanner/

See also https://blog.nraboy.com/2014/09/implement-barcode-scanner-using-ionic-framework/

Upvotes: 0

mfink
mfink

Reputation: 1380

Did you run the cordova cli command to install the barcodeScanner plugin? something like:

$ cordova plugin add <plugin url>

Upvotes: 0

Related Questions