bar code scanner using ionic framework

$scope.scanBarcode = function(){

$cordovaBarcodeScanner.scan().then(function(imageData){

  alert(imageData.text);

  console.log("Barcode format ->" + imageData.format);

  console.log("Cancelled ->" + imageData.cancelled);

  },
 function(error) {

  console.log("An error happened ->" + error);
 });

 };

these are the errors in console

Error: [$injector:unpr] Unknown provider: $cordovaBarcodeScannerProvider <- $cordovaBarcodeScanner <- AppCtrl http://errors.angularjs.org/1.3.13/$injector/unpr?p0=%24cordovaBarcodeScannerProvider%20%3C-%20%24cordovaBarcodeScanner%20%3C-%20AppCtrl at REGEX_STRING_REGEXP (ionic.bundle.js:8762) at ionic.bundle.js:12696 at Object.getService [as get] (ionic.bundle.js:12843) at ionic.bundle.js:12701 at getService (ionic.bundle.js:12843) at invoke (ionic.bundle.js:12875) at Object.instantiate (ionic.bundle.js:12892) at ionic.bundle.js:17161 at IonicModule.controller.self.appendViewElement (ionic.bundle.js:48253) at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.render (ionic.bundle.js:46450)(anonymous function) @ ionic.bundle.js:20306$get @ ionic.bundle.js:17256$get.Scope.$broadcast @ ionic.bundle.js:23421$state.transitionTo.$state.transition.resolved.then.$state.transition @ ionic.bundle.js:40889processQueue @ ionic.bundle.js:21888(anonymous function) @ ionic.bundle.js:21904$get.Scope.$eval @ ionic.bundle.js:23100$get.Scope.$digest @ ionic.bundle.js:22916$get.Scope.$apply @ ionic.bundle.js:23205done @ ionic.bundle.js:18358completeRequest @ ionic.bundle.js:18548requestLoaded @ ionic.bundle.js:18489XMLHttpRequest.send (async)(anonymous function) @ ionic.bundle.js:18526sendReq @ ionic.bundle.js:18327$get.serverRequest @ ionic.bundle.js:18043processQueue @ ionic.bundle.js:21888(anonymous function) @ ionic.bundle.js:21904$get.Scope.$eval @ ionic.bundle.js:23100$get.Scope.$digest @ ionic.bundle.js:22916$get.Scope.$apply @ ionic.bundle.js:23205bootstrapApply @ ionic.bundle.js:10147invoke @ ionic.bundle.js:12884doBootstrap @ ionic.bundle.js:10145bootstrap @ ionic.bundle.js:10165angularInit @ ionic.bundle.js:10059(anonymous function) @ ionic.bundle.js:34824trigger @ ionic.bundle.js:11443eventHandler @ ionic.bundle.js:11713

Make sure you have installed the plugin, from the project root execute:

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

You should inject $cordovaBarcodeScanner into your AppCtrl, something like:

angular.module('myapp').controller('AppCtrl', function ($scope, $cordovaBarcodeScanner) {
    $scope.scanBarcode = function(){
        $cordovaBarcodeScanner.scan().then(function(imageData){
                alert(imageData.text);
                console.log("Barcode format ->" + imageData.format);
                console.log("Cancelled ->" + imageData.cancelled);
            },
            function(error) {
                console.log("An error happened ->" + error);
            });
    };
});

Also make sure to test it on a real device instead of ionic serve, cordova serve or any emulator.

Seems you want to use the ngCordova wrapper for cordova plugin Barcode scanner. ngCordova isn't bundle in ionic

Do you add the ngCordova.js file in your index.html file ?

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

And add it at dependecy of your module

angular.module('mymodule', ['ngCordova'])

You can install it with Bower

 bower install ngCordova

Or download from the website http://ngcordova.com/