How can I retrieve data from an Angular Material Dialog Box and send it to the Parent component?
I am able to access data after the dialog box is closed. However, I am wondering if there is a way to retrieve data while the dialog box is still open, especially when a person clicks a button within the dialog box.
public openPropertySearchDialog(): void {
const propertySearchDialogRef = this.propertySearchDialog.open(PropertyGridDialogComponent,
{
width: '1500px',
height: '950px',
data: this.propertyList,
hasBackdrop: false
});
propertySearchDialogRef.afterClosed().subscribe(result => {
console.log('propertyResult', result);
});
}
Update:
The code above subscribes to the data. The challenge now is to retrieve data when a Button is clicked inside the Dialog component. I am considering adding another subscription for the button press event in a clean manner, rather than having two separate subscriptions.
propertySearchDialogRef .componentInstance.propertyOutput.subscribe((data: any) => {
console.log('test', data);
});
https://material.angular.io/components/dialog/api
Many resources online focus on retrieving data only when the window is closed. I am looking for a solution for retrieving data when the dialog box is open and a button is clicked (without closing the dialog box).
How to pass data to afterClosed() in Angular Material Dialog in Angular 6
Pass several data from Mat Dialog Angular 4 back to parent