I need to send modified values to an API and include the finalDate variable in the data. I am using reactive forms with a mat-stepper single form which is why I am using FormArray. Below is the code snippet:
onSubmit() {
const birthDateValue = (this.formGroup.get("formArray") as FormArray).at(0).get("birthDate").value;
const birthDateValueControl = (this.formGroup.get("formArray") as FormArray).at(0).get("birthDate");
const PeriodValue = (this.formGroup.get("formArray") as FormArray).at(1).get("period");
// send age as date
const date = new Date();
const year = date.getFullYear() - birthDateValue;
date.setFullYear(year);
const finalDate = date.toISOString();
//set value of carousel
PeriodValue.setValue(this.myCarousel.slideCounter + 3);
// send form as one object
const formArrayData = this.formGroup.get('formArray').value;
const data = formArrayData.reduce((prev, next) => ({
...prev,
...next
}), {})
console.log(data);
this.service.calculate(data).subscribe(
(res: any) => {
console.log(res);
},
err => {
console.log(err);
}
);
}
}