ngZorro-StaticInjectorError(AppModule)[覆盖]

时间:2019-10-11 07:49:36

标签: html angular typescript ant-design-pro ng-zorro-antd

我在我的项目中使用ng-zorro,在--prod之后出现以下错误。 通常情况下,服务器不会产生此错误。 我发现了这个git帖子https://github.com/NG-ZORRO/ng-zorro-antd/issues/3713#issuecomment-513933229 但是对我没用。

main-es2015.fa929b87a49d088ae223.js:36985 ERROR NullInjectorError: StaticInjectorError(AppModule)[Overlay]: 
  StaticInjectorError(Platform: core)[Overlay]: 
    NullInjectorError: No provider for Overlay!

我的package.json文件

{
  "name": "sporttzzmeetup",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.2.10",
    "@angular/cdk": "~8.2.1",
    "@angular/common": "~8.2.10",
    "@angular/compiler": "~8.2.10",
    "@angular/core": "~8.2.10",
    "@angular/forms": "~8.2.10",
    "@angular/platform-browser": "~8.2.10",
    "@angular/platform-browser-dynamic": "~8.2.10",
    "@angular/router": "~8.2.10",
    "core-js": "^2.5.4",
    "ng-zorro-antd": "^8.3.1",
    "rxjs": "~6.5.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.8",
    "@angular/cli": "~8.3.8",
    "@angular/compiler-cli": "~8.2.10",
    "@angular/language-service": "~8.2.10",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.5.3"
  }
}


在app.module.ts中导入 该项目可在ng服务器上正常工作。

@NgModule({
  declarations: [
    AppComponent,
    CommentsComponent,
  ],
  imports: [
    FlexLayoutModule,
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    HttpClientModule,
    BrowserAnimationsModule,
    NgZorroAntdModule
  ],
  providers: [
    GlobalService,
    RouteGuardService,
    { provide: HTTP_INTERCEPTORS, useClass: HttpAuthInterceptor, multi: true },
    { provide: NZ_I18N, useValue: en_US }],
  bootstrap: [AppComponent]
})
export class AppModule { }

1 个答案:

答案 0 :(得分:2)

要获得预期结果,请检查您的ng-zorro和angular版本,以避免由于版本不匹配而引起的错误