My function for selecting the date is working perfectly:
formatDateField(event: Date, formControl: string) {
this.form
.get(formControl)
.patchValue(
this.datePipe.transform(event.getTime(), "yyyy-MM-dd'T'HH:mm:ss")
);
}
Recently, I added a button to add days to the date using the code below. However, the developer's console shows "undefined" as an error message:
addDaysToDateForm(formName: string, days: number) {
let formDate: Date = this.form.get(formName).value || new Date();
formDate.setDate(formDate.getDate() + days);
this.form.get(formName).setValue(formDate);
}
setTodayForm(formName: string) {
this.form.get(formName).setValue(new Date());
}
Does anyone have any idea what could be wrong with it?