Within my application, there is a child dialog connected to a parent component. The parent component contains a MatTable that gets updated when the "update" button in the child dialog is clicked.
The following code in the parent component is functioning perfectly:
parentComponent.ts
openDialog(e: any) {
this.data = e;
const dialogRef = this.dialog.open(DialogAddMarqueComponent, {
data: this.data,
restoreFocus: false,
});
console.log(this.dialogRef)
dialogRef.afterClosed().subscribe((result) => {
if (result.length !== 0) {
this.products.data.push(result);
this.products = new MatTableDataSource(this.products.data);
} else { return; }
});
}
I have implemented a new function and button similar to the update functionality but without closing the DialogRef. I aim to replicate the behavior within dialogRef.afterClosed() without actually closing the dialog.
Child Component.ts
this.appService.addProduct(this.product)
.subscribe(
response => {
this.product = response;
this.products.data.unshift(response);
// this.dialog.close(response); // that will trigger the dialogRef.afterclosed()
}, error => {
console.warn('ERROR', error);
}
);
I believe I need to subscribe to the dialogRef on the parent side so that clicking the duplicate button triggers an update in the parent component. However, I am unsure of which dialogRef function to utilize (I attempted Get state). Is there a method to accomplish this?