I have a control form with a name 'question1'inside the form object parentForm, and I subscribed to it as follows.
Its a switch with two parameters Yesand Nowhen I select No, I receive Yesand when I select Yesit a No.
this.parentForm.controls['question1'].valueChanges.subscribe(
(selectedValue) => {
console.log(selectedValue);
console.log(this.parentForm.value['question1']);
}
);
selectedValuethe variable has the correct value, but if I do console.log(this.parentForm.value['question1'], it gives the previous value.
I tried putting setTimeout()before getting the value out this.parentForm.value['question1'], it just works fine.
setTimeout(() => {
console.log(this.parentForm.value['question1']);
}, 500);
But my question is why parentFormit is not updated when its control value changes, and that I also return its value only after the value has been changed.
. parentForm.valueChanges, .