当我发现错误时,我正在尝试打开MatSnackBar。我已经将其简化为这个,但仍然无法正常工作。
constructor(public matSnackBar: MatSnackBar) {
this.matSnackBar.open('test', 'Undo', {
duration: 3000
});
}
我一直收到相同的错误:ERROR Error: "Uncaught (in promise): TypeError: this._portalOutlet is undefined
。
我在我的@NgModule中将MatSnackBarContainer
添加到了提供者和entryComponents
答案 0 :(得分:0)
我通过导入MatSnackBarModule
并提供MatSnackBar
并将MatSnackBarContainer
添加到entryComponents来解决了这个问题
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserAnimationsModule,
MatSnackBarModule
],
providers: [ MatSnackBar, {
provide: MAT_DIALOG_DATA,
useValue: {}
}],
bootstrap: [AppComponent],
entryComponents: [MatSnackBarContainer]
})
export class AppModule {
}