我有一个包含是和否选项的对话框(确认框)。我想等到用户从对话框中按下是或否按钮,但现在单击按钮,即使在单击对话框中的选项之前,控制台日志也会打印初始/空字符串。
HTML:
<button (click)="foo()"></button>
零件:
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;
});
}