[英]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.