Search code examples
angularngb-datepicker

How to bind date from API to ng-bootstrap Datepicker in formGroup


Please find my issue below.

I'm using Angular 5 formGroup and ngbDatepicker for date input. Date picker is working for new form, Please let me know how to bind the date to the date picker through formGroup & formControlName.

Version of Angular and Bootstrap: Angular: 5 Bootstrap: 4


Solution

  • the only you need is that the input of ngbDatePicker was type of NgbDateStruct, that's is an Object with day,month and year properties

    this.dataForm = this.fb.group({
         "fecha":[{year:2018,month:1,day:21}]
    })