Hi hoping to get some help on this. I am trying to import Ionic’s native Barcode Scanner into my Ionic 5, Angular 9 app. I have capacitor installed and used the following method to install the barcode scanner:
npm install phonegap-plugin-barcodescanner
npm install @ionic-native/barcode-scanner
ionic cap sync
I then setup the barcode scanner in a component as follows:
import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';
constructor(private barcodeScanner: BarcodeScanner) { }
this.barcodeScanner.scan().then(barcodeData => {
console.log('Barcode data', barcodeData);
}).catch(err => {
console.log('Error', err);
});
This threw a null injector error. Seeing the forums it looked like you have to import the barcodescanner in app modules as a provider. I did this as follows in app.modules.ts:
import {BarcodeScanner} from '@ionic-native/barcode-scanner';
.....
providers: [
BarcodeScanner,
StatusBar,
SplashScreen,
FileTransfer, FileTransferObject,
File,
InAppBrowser,
Keyboard,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
UpdateService,
{
provide: HTTP_INTERCEPTORS,
useClass: HttpInterceptorService,
multi: true,
}
],
bootstrap: [AppComponent]
The issue is I now get the following error:
Invalid provider for the NgModule ‘AppModule’ - only instances of Provider and Type are allowed
Any one else come across this issue before and the solution? I haven’t installed cordova just capacitor which I understand is all I need, is this correct?
Appreciate any help on this as I am at a dead end. Below ionic info + version of barcde scanner installed. Many thanks in advance.
@ionic-native/barcode-scanner": "^5.26.0",
@ionic-native/core": "^5.26.0
Ionic:
Ionic CLI : 5.4.15 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 5.1.1
@angular-devkit/build-angular : 0.901.7
@angular-devkit/schematics : 9.1.7
@angular/cli : 9.1.7
@ionic/angular-toolkit : 2.2.0
Capacitor:
Capacitor CLI : 2.1.2
@capacitor/core : 2.1.2
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (0 plugins total)
Utility:
cordova-res : not installed
native-run : not installed
System:
NodeJS : v12.14.1 (/usr/local/bin/node)
npm : 6.13.4
OS : macOS Catalina
Xcode : Xcode 11.5 Build version 11E608c
1 post - 1 participant