在对话框组件中,可以通过MatDialogRef来关闭对话框,并返回对话框结果。为了在提交时刷新页面而不关闭对话框,可以通过将MatDialogRef的close方法参数设置为false来实现。
示例代码:
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'app-dialog-example',
templateUrl: './dialog-example.component.html',
styleUrls: ['./dialog-example.component.css']
})
export class DialogExampleComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: any
) { }
ngOnInit() {
}
onSubmit() {
// 刷新页面逻辑
location.reload();
// 关闭对话框并返回结果
this.dialogRef.close(false);
}
}