[英]Angular 7: NullInjectorError: No provider for MatSnackBarConfig
In our project we use Angular 7
and Angular Material
.在我们的项目中,我们使用
Angular 7
和Angular Material
。 Everything is fine under Google Chrome
but under Internet Explorer 11
, when the app is run with --aot
flag, we receive the following error:在
Google Chrome
下一切正常,但在Internet Explorer 11
,当应用程序使用--aot
标志运行时,我们收到以下错误:
ERROR Error: StaticInjectorError(AppModule)[MatSnackBarContainer -> MatSnackBarConfig]:
StaticInjectorError(Platform: core)[MatSnackBarContainer -> MatSnackBarConfig]:
NullInjectorError: No provider for MatSnackBarConfig!
The Material
modules are imported in a separate file as: Material
模块在单独的文件中导入为:
import { NgModule } from '@angular/core';
import {
...
MatSnackBarModule,
...
} from '@angular/material';
@NgModule({
exports: [
...
MatSnackBarModule,
...
],
})
export class MyMaterialModule { }
Please note: the app works just fine under Google Chrome
!请注意:该应用程序在
Google Chrome
下运行良好! Any ideas?有任何想法吗? Thanks for looking into this!
感谢您查看这个!
This error usually occurs when the service you are trying to use has not been provided in your @NgModule. 当您尝试使用的服务未在@NgModule中提供时,通常会发生此错误。
To use the MatDialog
service, you will need to go to your module file and add MatSnackBarModule
to the array of imports: 要使用
MatDialog
服务,您需要转到模块文件并将MatSnackBarModule
添加到导入数组中:
import {MatSnackBarModule} from '@angular/material';
@NgModule({
imports: [MatSnackBarModule]
})
export class MyMaterialModule {}
Your code should be like this 你的代码应该是这样的
import {MatSnackBarModule} from '@angular/material';
@NgModule({
imports: [MatSnackBarModule],
exports: [
...
MatSnackBarModule,
...
],
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.