I have a component that uses two date fields, a start date & and end date.
By default, I have my end date field disabled and I toggle it when they select a start date.
this.transitionForm = this.fb.group({
effectiveEndDate: [{ value: '', disabled: true }]
.....
});
I am trying to set the value of this end date field within my code.
this.transitionForm.controls['effectiveEndDate'].setValue(this.utils.currentDate());
Utility Function:
/**
* Returns the current date
*/
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 getting updated though.
I have also tried to use PatchValue
and that wasn't setting it either.
What am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…