Yogi Bear
Yogi Bear

Reputation: 963

bootstrap ngbDatePicker how to programmatically set a date

We are using ngbDatePicker in our application. Due to other user actions, we need to programmatically set the date in the calendar to not only show the new month, but specifically highlight the DAY we want to select.

NavigateTo only sets the year and month.

I thoroughly reviewed the documentation; closest I've found is the open() function, which is supposed to set it to the current ngModel value - couldn't get this to work.

Upvotes: 1

Views: 8788

Answers (1)

Eliseo
Eliseo

Reputation: 57929

//using Template Drive From
    <ngb-datepicker #dp [(ngModel)]="myDate"></ngb-datepicker>

    myDate={year:2018,month:3,day:28}

//using Reactive Form
   <form [formGroup]="myForm">
    <ngb-datepicker #dp formControlName="myDate"></ngb-datepicker>
  </form>

  this.myForm=this.fb.group({
    myDate:[{year:2018,month:3,day:28}]
  })

Upvotes: 9

Related Questions