I've noticed that when I try to update a couple values in my FormBuilder right before submitting it with HTTPclient my values aren't updated. When I run the submit a 2nd time these values are updated.
private mergeDates(dateValue: string, timeValue: string): string {
const returnValue = dateValue.toString().replace(' 00:00', ` ${timeValue}`);
return returnValue;
}
private submitVacancy() {
if (this.vacancyForm.invalid) {
return;
}
const fValue = this.vacancyForm.value;
const fControls = this.vacancyForm.controls;
fControls['beginDateTime'].setValue(
this.mergeDates(fValue['beginDate'], fValue['beginTime']),
);
fControls['endDateTime'].setValue(
this.mergeDates(fValue['beginDate'], fValue['endTime']),
);
alert(JSON.stringify(fValue));
this.http.post(`${this.apiUri}/addvacancy`, JSON.stringify(fValue));
}
JSON.stringify(fValue)?fValuevariable before callingsetValuemethod on form controls. Try to move this assignment just above the line withalertfunction call.