Search code examples
cordova-pluginsionic-framework

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?


Solution

  • 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/