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

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
min
  • 11
  • 1
  • 1
    Possible duplicate of https://stackoverflow.com/questions/45330319/angular2-setting-date-field-on-reactive-form – Syed Ali Taqi Apr 17 '19 at 05:15
  • 1
    Possible duplicate of [Angular2 - Setting date field on reactive form](https://stackoverflow.com/questions/45330319/angular2-setting-date-field-on-reactive-form) – Syed Ali Taqi Apr 17 '19 at 05:15

2 Answers2

1

For date type input you need to convert the date

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

Demo

Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
0

You can do as follow

const date = new Date();
this.createForm.controls['startDateInput'].setValue(date)
ram12393
  • 1,284
  • 3
  • 14
  • 29