[英]this._portalOutlet is undefined when trying to open a MatSnackBar
当我发现错误时,我试图打开一个 MatSnackBar。 我已经将它简化为这个,但我仍然无法让它工作。
constructor(public matSnackBar: MatSnackBar) {
this.matSnackBar.open('test', 'Undo', {
duration: 3000
});
}
我不断收到相同的错误: ERROR Error: "Uncaught (in promise): TypeError: this._portalOutlet is undefined
。
我在MatSnackBarContainer
添加到 providers 和 entryComponents
我通过导入MatSnackBarModule
以及提供MatSnackBar
并将MatSnackBarContainer
添加到 entryComponents 来解决它
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserAnimationsModule,
MatSnackBarModule
],
providers: [ MatSnackBar, {
provide: MAT_DIALOG_DATA,
useValue: {}
}],
bootstrap: [AppComponent],
entryComponents: [MatSnackBarContainer]
})
export class AppModule {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.