我正在使用棱 Angular Material dialogcomponent在我的 Angular 应用程序中,每当服务器出现错误时打开一个对话框。
如果同时出现多个错误,它会打开多个对话框,这对我来说很好。我想使用 closeAll
一次关闭所有对话框方法。
当尝试使用 closeAll
得到此错误的方法:
error TS2339: Property 'closeAll' does not exist on type 'MatDialogRef<DialogComponent, any>'.
我如何打开对话框:
constructor(private dialog: MatDialog) {}
const dialogRef = this.dialog.open(DialogComponent, {
width: "500px",
height: "500px",
disableClose: true,
hasBackdrop: true,
data: { name: this.name, animal: this.animal }
});
对话框组件.ts
onClose(): void {
this.dialogRef.closeAll();
}
app.module.ts
@NgModule({
declarations: [
DialogComponent,
...
],
imports: [
MatDialogModule,
BrowserAnimationsModule,
...
],
providers: [
...
],
entryComponents: [ DialogComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
谁能帮帮我吗?
最佳答案
将 MatDialog 注入(inject) DialogComponent.ts
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material';
export class DialogComponent {
constructor(private _dialog: MatDialog) { }
public onClose(): void {
this._dialog.closeAll();
}
}
关于angular - 如何一次关闭使用 Angular Material 打开的所有对话框模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49824014/