【发布时间】:2020-09-19 19:50:49
【问题描述】:
我正在使用 Angular 9,并且有一个 Material 对话框,设置为在关闭时返回 "test",如下所示:
<mat-dialog-actions align='center'>
<button mat-raised-button color='primary' [mat-dialog-close]='"test"'>
Submit
</button>
</mat-dialog-actions>
在我的主页组件中,我订阅了 afterAllClosed:
constructor(private matDialog: MatDialog) { }
OpenMatDialog(data): void {
this.matDialog.open(
DialogComponent,
{ data },
);
if( !this.matDialogCloseSub$ )
this.matDialogCloseSub$ = this.matDialog.afterAllClosed.subscribe(result => {
console.log(result);
});
}
但是,result 总是以 undefined 的形式返回。我做错了什么?
我在entrycomponents中设置了app.module.ts中的对话框组件如下:
@NgModule({
declarations: [
AppComponent,
DialogComponent
],
imports: [
MatDialogModule,
],
entryComponents: [
DialogComponent,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
【问题讨论】: