2
我有一個對話框,選擇yes和no選項(確認框)。我想等到用戶按下對話框中的yes或no按鈕,但現在單擊按鈕時,即使在單擊對話框中的選項之前,控制檯日誌也會打印初始/空字符串。MD對話框材料Angular 2等待關閉
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;
});
}