Kri*_*hna 4 angular-material angular angular-material-5
每当服务器出现错误时,我都会在我的 angular 应用程序中使用 angular material dialogcomponent来打开一个对话框。
如果同时出现多个错误,它会打开多个对话框,这对我来说很好。我想使用closeAll方法一次关闭所有对话框。
当尝试使用closeAll获取此错误的方法时:
error TS2339: Property 'closeAll' does not exist on type 'MatDialogRef<DialogComponent, any>'.Run Code Online (Sandbox Code Playgroud)
我如何打开对话框:
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 }
});Run Code Online (Sandbox Code Playgroud)
对话框组件.ts
onClose(): void {
this.dialogRef.closeAll();
}Run Code Online (Sandbox Code Playgroud)
@NgModule({
declarations: [
DialogComponent,
...
],
imports: [
MatDialogModule,
BrowserAnimationsModule,
...
],
providers: [
...
],
entryComponents: [ DialogComponent],
bootstrap: [AppComponent]
})
export class AppModule {}Run Code Online (Sandbox Code Playgroud)
谁能帮帮我吗?
将 MatDialog 注入 DialogComponent.ts
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material';
export class DialogComponent {
constructor(private _dialog: MatDialog) { }
public onClose(): void {
this._dialog.closeAll();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3691 次 |
| 最近记录: |