I have a component that uses two date fields, a start date and an end date.
By default, my end date field is disabled, and I switch it when they select the start date.
this.transitionForm = this.fb.group({
effectiveEndDate: [{ value: '', disabled: true }]
.....
});
I am trying to set the value of this end date field in my code.
this.transitionForm.controls['effectiveEndDate'].setValue(this.utils.currentDate());
Useful feature:
currentDate() {
const currentDate = new Date();
const day = currentDate.getDate();
const month = currentDate.getMonth() + 1;
const year = currentDate.getFullYear();
return month + "/" + day + "/" + year;
}
HTML:
<input type="date" class="form-control input-sm" id="effectiveEndDate" name="effectiveEndDate" placeholder="Required" formControlName="effectiveEndDate">
For some reason, the field is not updated.
I also tried to use PatchValue, and this also did not install.
What am I missing?
source
share