我在我的项目中使用 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 { }