TypeError: Cannot read property 'scan' of undefined

Hello community,
im sitting over 4 hours and trying any possible suggestion, but no one works for me.
Im including follow cordova plugin “https://github.com/wildabeast/BarcodeScanner.git”.
Im also including the ngCordova.min.js file and declare it in the module.

So far so good, but when im inject $cordovaBarcodeScanner, then it tells me that it is an object and my intellj detect the “scan” function, but when i execute it, it tells me the error as described in the title.
That’s what i do in the controller:
$ionicPlatform.ready(function () { $cordovaBarcodeScanner.scan(function (e) { alert("OK"); }, function (err) { console.log(err) }); });
Heindent preformatted text by 4 spacesre is the full stacktrace the Logcat prints me out:
[INFO:CONSOLE(25642)] "TypeError: Cannot read property 'scan' of undefined at Object.scan (file:///android_asset/www/js/ng-cordova.min.js:7:5751) at file:///android_asset/www/js/controllers.js:10:32 at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:53329:19 at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2135:9) at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:53327:26) at vm.scan (file:///android_asset/www/js/controllers.js:9:22) at new <anonymous> (file:///android_asset/www/js/controllers.js:17:8) at invoke (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17762:17) at Object.instantiate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17770:27) at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:22326:28", source: file:///android_asset/www/lib/ionic/js/ionic.bundle.js (25642)

I also tried to call it via cordova.plugins.barcodescanner, but this wont work either…can anyone help me?

Are you testing on your browser? You should test on a real device.

Hi, im testing on a real device.

The wildabeast-Repository is deprecated and should not be used any more, use the recommended successor at https://github.com/phonegap/phonegap-plugin-barcodescanner.

How did you include the plugin in you Ionic project?

Also, you should probably use it this way:

$cordovaBarcodeScanner.scan().then(function (imageData) {
  alert("OK");
}, function (err) {
  console.log(err)
});

I think intellij is suggesting strange things…

1 Like

Hi Sujan12,
i did now the same as it stands in GitHub.

  1. i removed the barcodeScanner plugin and then i added it via “phonegap plugin add phonegap-plugin-barcodescanner”

  2. In my Controller, i tried to call it via:
    $cordovaBarcodeScanner.scan().then(function (imageData) {

    });

But that’s what LogCat gives me:
[INFO:CONSOLE(25642)] “TypeError: Cannot read property ‘scan’ of undefined
at Object.scan (file:///android_asset/www/js/ng-cordova.min.js:7:5751)
at Scope.$scope.test (file:///android_asset/www/js/controllers.js:8:30)
at fn (eval at (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:26457:15), :4:203)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:62386:9
at Scope.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:29158:28)
at Scope.$apply (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:29257:23)
at HTMLElement. (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:62385:13)
at HTMLElement.eventHandler (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:16583:21)
at triggerMouseEvent (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2948:7)
at tapClick (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2937:3)”, source: file:///android_asset/www/lib/ionic/js/ionic.bundle.js (25642)

I tried this approach before too. As i said, i tried every possible approach :tired_face:

Create a new Ionic project, only add the barcode plugin and the code to use it, upload to a new repository on Github - then we can have a look at it. Something you are forgetting - I have a project running exactly this code and plugin that works fine.

Hi Sujan12,
i started my old notebook and tried to do the same as i did before with the barcodescanner…and it worked on the first time.

I guess that something is wrong with my new laptop.
I thank you very much for your help.

Sincerly,

Alex

1 Like