I have a dialog with yes and no options(confirmation box). I want to wait till the user press yes or no button from dialog, but right now on button click, even before clicking the options in dialog box, console log prints initial/empty string.
HTML:
<button (click)="foo()"></button>
Component:
selectedOption = '';
foo() {
this.openDialog();
console.log('selectedOption: ' + this.selectedOption); // Prints initial Value
// hit the API if selectedOption is yes.
}
openDialog() {
dialogRef.afterClosed().subscribe(result => {
this.selectedOption = result;
});
}