0

I have a FormGroup that takes date from a date input.

FormControl:

dob: new FormControl(new Date()),

Assigning new Date() to get the default date, in case no date is selected.

Template:

<input type="date" formControlName="dob">

However, when I am using patchValue to populate the date (from a previously persisted object), it is not workning/showing up in the date input tag's text (in the webpage). What am I missing?

1
  • 1
    a input type date manage "strings" Commented Apr 8, 2021 at 11:02

1 Answer 1

3

You should format the date using formatDate function form @angular/common namespace before the patch or initialize.

E.g: dob: new FormControl(formatDate(new Date(), "yyyy-MM-dd", "en"))

Working demo at StackBlitz.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.