1

I am new to angular. I have an input with type date. How will I bind the date to this input?

<input type="date" class="form-control" formControlName="startDateInput">

i tried the following but it didn't work:

this.createForm.patchValue({
    startDateInput:this.resourceData['period'].start,
});

please help to do this

2

2 Answers 2

1

For date type input you need to convert the date

this.createForm.patchValue({ 
    startDateInput: (new Date()).toISOString().substring(0,10), 
});

Demo

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

Comments

0

You can do as follow

const date = new Date();
this.createForm.controls['startDateInput'].setValue(date)

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.