簡體   English   中英

嘗試打開 MatSnackBar 時 this._portalOutlet 未定義

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM