Noob: barcode scanner issue ngCordova and Ionic


#1

Hello,
I am stuck getting the barcode scanner plugin to work.
USB debugging my native Android I get the following result:

\ionic.bundle.js:26799 TypeError: Cannot read property ‘scan’ of undefined
at ChildScope.$scope.scanBarcode (controllers.js:11)
at fn (eval at compile (ionic.bundle.js:27643), :4:224)

I have installed the latest barcode plugin:

bleep# cordova plugin add https://github.com/Telerik-Verified-Plugins/BarcodeScanner

bleep# ionic plugin ls
com.phonegap.plugins.barcodescanner 6.0.4 “BarcodeScanner”

in index.html I have:

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

and the controller is:
angular.module(‘app.controllers’, [])

.controller(‘scanModeCtrl’, [’$scope’, ‘$stateParams’,’$ionicPopup’, function ($scope, $stateParams,$ionicPopup,
$cordovaBarcodeScanner) {
$scope.selected = undefined;
$scope.location = Location;

$scope.data = {}
$scope.scanBarcode = function() {
        console.log('scanning');

        $cordovaBarcodeScanner.scan().then(function(barcodeData) {
            alert(JSON.stingify(barcodeData));
          }, function(error) {
            console.log("An error happened ->" + error);
          });

I am unable to find why this is not working. I an quite new to Ionic, but had the barcode plugin working just fine in a jquery phonegap application, so I do know what to expect.

Any help is welcome, for this is locking any progress for over 2 days now and slowly driving me crazy.


#2

Found the solution,
forgot to add $cordovaBarcodeScanner

.controller(‘scanModeCtrl’, [’$scope’, ‘$stateParams’,’$ionicPopup’,’$cordovaBarcodeScanner’,
function ($scope, $stateParams,$ionicPopup,$cordovaBarcodeScanner) {