Reputation: 88
The code is as follows:
import { Component } from '@angular/core'; import { NavController, Platform } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { BarcodeScanner } from '@ionic-native/barcode-scanner'; @Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { constructor(public navCtrl: NavController, private translate: TranslateService, private barcodeScanner: BarcodeScanner) { } //Switch language changelanguage() { let browserLang = this.translate.currentLang; this.translate.use(browserLang.match(/en/) ? 'zh' : 'en'); } //Scan test ScanCode() { this.barcodeScanner.scan() .then((result) => { console.log(result); }) .catch((error) => { alert(error); }); } }
Error Picture:
Reference:https://ionicframework.com/docs/native/barcode-scanner/
new questions arose:
According to Suraj recommendations, the prompt "plugin_not_installed"
Error Picture:
development environment:
Visual Studio 2017
Upvotes: 7
Views: 10754
Reputation: 746
I had the same issue with ionic cli 3.9.2.
I solved it using npm i @ionic-native/barcode-scanner@beta --save
.
import { BarcodeScanner } from "@ionic-native/barcode-scanner/ngx";
@NgModule({
...
providers: [
...
BarcodeScanner
...
]
...
})
export class AppModule { }
Upvotes: 4
Reputation: 387
I got same issue at android device after installing ionic cordova plugin add phonegap-plugin-barcodescanner --save
which error message is plugin_not_installed
. Just added CAMERA_USAGE_DESCRIPTION
variable inside phonegap-plugin-barcodescanner
tag at config.xml
and working :)
<plugin name="phonegap-plugin-barcodescanner" spec="^7.0.1">
<variable name="CAMERA_USAGE_DESCRIPTION" value=" " />
</plugin>
Upvotes: 1
Reputation: 29635
You need to set the scanner as provider in app.module.ts
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
@NgModule({
...
providers: [
...
BarcodeScanner
...
]
...
})
export class AppModule { }
Reference: Add Plugins to Your App's Module here
UPDATE:
From your package.json it looks like you have installed older ionic-native - 2.4.1
.Remove it and do:
npm install --save @ionic-native/core
Upvotes: 20