Cannot read property 'barcodescanner' of undefined cordova

Dear Team, I am trying to implement BarcodeScanner with ngCardova but didn’t got succeeded.
I followed instruction to install the BarcodePlugin GitHub - wildabeast/BarcodeScanner: Official repository now at [phonegap/phonegap-plugin-barcodescanner](http://github.com/phonegap/phonegap-plugin-barcodescanner).
and tried with ngCardova http://ngcordova.com/docs/ then getting following error:

"cannot read property ‘barcodescanner’ of undefined cordova
file: ng-codova.min.js : 229

On index page taken following ref:

<script src="cordova.js"></script>       
<script src="js/ionic.bundle.min.js"></script>
<script src="barcodescanner.js"></script>         
script src="js/ng-cordova.min.js"></script>  

app.js

angular.module('mobireward', [
    'ionic',         
    'ngCordova',

and in Controller

  .controller('MainCtrl', function ($scope, $rootScope, $location, $window, $ionicPopup, $ionicLoading, $cordovaBarcodeScanner ) {		
       
        $rootScope.scan = function () {
			  $cordovaBarcodeScanner.scan().then(function(result) {
			    // Scanner result
			  }, function(err) {
			  });   
        }

please help in where i am missing?

Just curious, why are you referencing the barcode scanner? If you installed the js through the command line, it will be loaded by cordova.

Try removing that, as it could be causing an conflict with angular.

I removed it but getting the same error. I am having doubt about the plugin integration:

in Plugin.xml mentioned: Does it required?

<js-module src="www/barcodescanner.js" name="BarcodeScanner">
    <clobbers target="cordova.plugins.barcodeScanner" />
</js-module>

In Config.xml mentioned:

 <feature name="BarcodeScanner">
  <param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
</feature>

Is this correct?

in menifest file added:

<activity android:name=“com.google.zxing.client.android.CaptureActivity”

android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>

<activity android:name=“com.google.zxing.client.android.encode.EncodeActivity”

android:label="@string/share_name">
<action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
<category android:name="android.intent.category.DEFAULT"/>

I am struggling since last one day but no success. Please can you suggest me is correct way to configure the plugin?

How are you installing the plugin, thought the CLI? You shouldn’t need to manually add these things.

Try this:

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

No I don’t have idea about CLI. Added the library project in eclips and then added refrence in our phonegap project.I following this instruction:

If it’s easy way to install through the CLI? then please could you suggest me how to configure it?

open console, use “cd …” or “cd < folder >” to navigate to your ionic folder (wich contains the folders www and platforms, etc)

Then write: cordova plugins ls (this will list all your cordova plugins, and will help you determinate if the barcode scanner is installed or not (i think not)

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

this will install the plugin on your project, and everytime you use cordova build, the plugin will be included on your project.

Then, ngcordova will work

This command is not work for me as I didn’t installed Node.Js.

Now installed everything with Cordova CLI. But still ngCordova is working for me as getting below error:

ReferenceError: options is not defined
ng-cordova.min.js: 301

Please suggest me still doing any mistakes?

@Bonda I followd your instruction but still showing the same error “barcodescanner” undefined

D:\E\Projects\Dev\Eclips\Mobi\mobirewarduser>cordova plugins ls
com.phonegap.plugins.barcodescanner 1.0.1 “BarcodeScanner”

D:\E\Projects\Dev\Eclips\Mobi\mobirewarduser>

When I run the add plugin: then got the message, it’s already installed:

Plugin “com.phonegap.plugins.barcodescanner” already installed on android.

D:\E\Projects\Dev\Eclips\Mobi\mobirewarduser>

index.html

 <script src="cordova.js"></script>       
 <script src="js/ionic.bundle.min.js"></script>    
 <script src="js/ng-cordova.js"></script>  

app.js

angular.module('mobireward', [

	'ionic',         
    'ngCordova',
	'mobireward.factory',	
	'mobireward.controllers',
    'mobireward.servies',    
    
])

controller

 .controller('MainCtrl', function ($scope, $rootScope, $location, $window, $ionicPopup, $ionicLoading, $cordovaBarcodeScanner) {		
		
		$rootScope.scan = function () {        	
        	alert("scan called");
			$cordovaBarcodeScanner.scan().then(function(result) {
			alert(result);
		    // Scanner result
		  }, function(err) {
		  });

		}

@Bonda I followd your instruction but still showing the same error “barcodescanner” undefined

D:\E\Projects\Dev\Eclips\Mobi\mobirewarduser>cordova plugins ls
com.phonegap.plugins.barcodescanner 1.0.1 “BarcodeScanner”

D:\E\Projects\Dev\Eclips\Mobi\mobirewarduser>

Finally got working. I dont know my changes is correct or not. I was getting error

options is not defined” in ng-cordova.js on line " 24.

and the code was :

 scan: function () {
      var q = $q.defer();         
      cordova.plugins.barcodeScanner.scan(function (result) {          
          q.resolve(result);
      }, function (err) {        
        q.reject(err);
      });
      //}, options); // Commented by me

      return q.promise;
    },

So I commented the options code line and then got it working

Thank you so much @Bonda and @mhartington for giving ideas and helping out from this issues.

@pahamad There was an error in the BarcodeScanner plugin. Fixed now: https://github.com/driftyco/ng-cordova/pull/45

1 Like

Thanks @pbernasconi I will take new version.

With your index.html I found out you were declaring nd-Cordova.js after cordova.js unlike what is mentioned in the docs

NOTE: Include ng-cordova.js in your index.html file before cordova.js:

@rushme1986 issue was with plugin js file and as i mentioned in previous post. I resolved it and even ng-cordova team already maded changes for the same.

Thats great…can you contribute something to my query in http://tinyurl.com/ionicerr @pahamad