首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >离子:错误: NgModule 'AppModule‘的无效提供程序

离子:错误: NgModule 'AppModule‘的无效提供程序
EN

Stack Overflow用户
提问于 2021-01-22 15:52:38
回答 1查看 498关注 0票数 0

我使用以下命令在我的离子应用程序中安装了Barcodescanner

代码语言:javascript
复制
ionic cordova plugin add phonegap-plugin-barcodescanner
npm install @ionic-native/barcode-scanner

安装之后,我导入它,然后在app.moule.ts中也添加到提供者列表中,如下所示

代码语言:javascript
复制
 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 {}

之后,我将其注入构造函数中,如下所示:

代码语言:javascript
复制
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() {
  }

}

这给我带来了以下错误:

代码语言:javascript
复制
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

有人能帮忙解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2021-01-22 17:12:47

您不需要在BarcodeScanner提供程序列表中导入AppModule

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65848406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档