我有一个调用GET
请求的垫表。另外我有一个 Mat 对话框,它接受数据和保存点击调用POST
请求。一切正常,但有时在单击“保存”按钮后表格会更新,但有时不会(我必须重新加载页面并查看更新)。
mat-dialog.component.ts
onSubmit() { // This method is called on the button click in Mat-Dialog
if(this.formdata.invalid) {
return;
}
this.adminService.createQuestionCategory(this.formdata.value).subscribe(reponse => {
this._snackBar.open('New Question Category Added Successfully', '', {
duration: 7500,
horizontalPosition: this.horizontalPosition,
verticalPosition: this.verticalPosition
});
});
}
主要组件.ts
constructor(private adminCategory: AdminCategoryService, private fb: FormBuilder, public dialog: MatDialog) {
dialog.afterAllClosed.subscribe(() => {
console.log(''); // This line gets called everytime on close of the modal
this.getTableData(); // So this line also gets called but not re-render the template updated everytime
});
}
openDialog() {
this.dialog.open(CreateSectionModalComponent);
}
private getTableData() {
this.columnsToDisplay = ['id', 'questionCategoryName', 'isActive', 'Action'];
this.adminCategory.getQuestionCategory().subscribe((reponse: any) => {
this.QuestionCategoryData = reponse.questionCategoryList;
this.dataSource = new MatTableDataSource<QuestionCategory>(this.QuestionCategoryData);
this.dataSource.paginator = this.paginator;
}, error => {
console.log(error);
});
}
ngOnInit() {
this.getTableData();
}
有什么遗漏吗?