Barcode 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 errors in the 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 on REGEX_STRING_REGEXP (ionic.bundle.js: 8762) on ionic.bundle.js: 12696 in Object.getService [ionic.getService bundle.js: 12843) at ionic.bundle.js: 12701 at getService (ionic.bundle.js: 12843) when calling (ionic.bundle.js: 12875) in Object.instantiate (ionic.bundle.js: 12892) at ionic.bundle.js: 17161 in IonicModule.controller.self.appendViewElement (ionic.bundle.js: 48253) in 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.s 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: 10165Bangularleit @ ionic59 (anonymous function) @ionic.bundle.js: 34824trigger @ ionic.bundle.js: 11443eventHandler @ ionic.bundle.js: 11713

+3


source to share


2 answers


It looks like you want to use the ngCordova wrapper for Cordova barcode plugins. ngCordova is not bundle in ionic

Are you adding the ngCordova.js file to your index.html file?

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

      

And add it to the 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/

+3


source


Make sure you have installed the plugin from the project executable:

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

      

You must enter $cordovaBarcodeScanner

into yours 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 test it on a real device instead of ionic serve

, cordova serve

or any emulator.

+1


source







All Articles