Looking for a way to pass true/false boolean data from a dialog box into the parent component without just console logging the result? You want to store it in a variable in the parent component for further use. Any suggestions on how to achieve this?
This is the code snippet of my parent component :
openDialog( dialogData : any )
{
let dialogRef = this.dialog.open(DialogExampleComponent, {data : dialogData});
dialogRef.afterClosed().subscribe(result => {
console.log(result);
});
}
This is the HTML of my dialog component:
<h2 mat-dialog-title>Delete Element?</h2>
<mat-dialog-content>Are you sure you want to delete '{{dialogData.content}}'' from '{{dialogData.column}}'</mat-dialog-content>
<mat-dialog-actions>
<button mat-button mat-dialog-close mat-dialog-close="true">Delete</button>
<button mat-button mat-dialog-close mat-dialog-close="false">Cancel</button>
</mat-dialog-actions>
And here is the TypeScript code of my dialog component:
import { Component, OnInit,Inject } from '@angular/core';
import { 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(@Inject(MAT_DIALOG_DATA) public dialogData : any) { }
ngOnInit(): void {
}
}