My goal is to retrieve the date from the first input control and the number of days from the other input controls, add them together, and assign the result to the third date control using TypeScript. However, I am encountering an error with the following code:
activeFrom: Date;
activeNoDays: number;
// UpdateExpiry Function is called by the textbox event
updateExpiry = (): void => {
this.gDetailDS = this.gDetailForm.value;
console.log("Expiry days:" + this.gDetailDS.activeNoDays);
console.log(this.addDays(this.gDetailDS.activeFrom, this.gDetailDS.activeNoDays))
}
addDays(date: Date, days: number): Date {
console.log('adding ' + days + ' days');
console.log(date);
date.setDate(date.getDate() + days);
console.log(date);
return date;
}
This is the HTML for the controls:
<input
id="txtActivateFrom"
type="date"
min="rdMinDate"
formControlName="activeFrom"
class="form-control"
value="{{ this.gDetailDS.activeFrom | date:'yyyy-MM-dd' }}"
displayFormat="yyyy-MM-dd"
useValueAsDate />
<input type="number"
formControlName="activeNoDays" class="form-control"
(change)="updateExpiry()"/>
Console Messages:
Expiry days:25
adding 25 days
2019-07-12
Despite trying everything, I am still facing this issue:
ERROR TypeError: date.getDate is not a function
Link: screenshot of the error appearing on the browser console