我使用以下命令在我的离子应用程序中安装了Barcodescanner
ionic cordova plugin add phonegap-plugin-barcodescanner
npm install @ionic-native/barcode-scanner安装之后,我导入它,然后在app.moule.ts中也添加到提供者列表中,如下所示
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import {BarcodeScanner} from '@ionic-native/barcode-scanner/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
BarcodeScanner
],
bootstrap: [AppComponent]
})
export class AppModule {}之后,我将其注入构造函数中,如下所示:
import { Component, OnInit } from '@angular/core';
import {BarcodeScanner} from '@ionic-native/barcode-scanner/ngx';
@Component({
selector: 'app-scanning',
templateUrl: './scanning.page.html',
styleUrls: ['./scanning.page.scss'],
})
export class ScanningPage implements OnInit {
constructor( barcodeScanner: BarcodeScanner) {
}
ngOnInit() {
}
}这给我带来了以下错误:
Error: Invalid provider for the NgModule 'AppModule' - only instances of Provider and Type are allowed, got: [..., ..., ..., ?[object Object]?]
at throwInvalidProviderError (core.js:5455)
at providerToFactory (core.js:11347)
at providerToRecord (core.js:11318)
at R3Injector.processProvider (core.js:11216)
at core.js:11202
at core.js:1135
at Array.forEach (<anonymous>)
at deepForEach (core.js:1135)
at R3Injector.processInjectorType (core.js:11202)
at core.js:11009我试过很多次来解决这个问题,但是找不出原因,下面是我的离子版本
6.12.3
节点版本
12.19.0
有人能帮忙解决这个问题吗?
发布于 2021-01-22 17:12:47
您不需要在BarcodeScanner提供程序列表中导入AppModule
https://stackoverflow.com/questions/65848406
复制相似问题