I've a Mat Table which calls a GET
request. Also I've a Mat Dialog which takes data and on Save click calls POST
request. Everything is working fine but the table sometimes get updated after I click the Save button but sometimes not (I've to reload the page and to see it updated).
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
});
});
}
main.component.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();
}
Is there anything am missing ?