I use angular 10. I have a modal with a date input. I would like to assign today date.
In a component, I have
addEventForm: FormGroup;
addEventFormInitialValues = {
eventType: ['', Validators.required],
eventDate: ['', Validators.required]
};
In the constructor I tried
this.addEventFormInitialValues.eventDate = this.datepipe.transform(new Date(), 'yyyy-MM-dd');
I get this error
error TS2322: Type 'string' is not assignable to type '(string | ((control: AbstractControl) => ValidationErrors))[]'.
I also tried
eventDate: [new Date(), Validators.required]
I don't get error but I don't have any default date displayed
<div class="form-group row">
<label for="eventDate" class="col-sm-3 col-form-label">{{'addEvent.eventDate' | translate}}</label>
<div class="col-sm-3 self-center">
<input type='date' id="eventDate" formControlName="eventDate"/>
<p class="no-bottom-margin">
<app-form-validation-hint *ngIf="addEventSubmitted && eventAddForm.eventDate.errors && eventAddForm.eventDate.errors.required"></app-form-validation-hint>
</p>
</div>
</div>