Angular 4 Date-Picker - How to restrict Future and Past Days

D.Sridhar picture D.Sridhar · Jun 20, 2018 · Viewed 17.9k times · Source

I want to restrict the future and past days using Angular 4 Date-Picker.I just want to enable Current Date[today] only.How can i solve this.

Can anyone have idea...???

This is my template:

<input type="text" placeholder="FromDate" class="form-control" 
  placement="top"
  formControlName="fromDate" 
  [bsConfig]="{ dateInputFormat: 'DD-MM-YYYY' }" 
  bsDatepicker style="padding: 16px">

Answer

maury844 picture maury844 · Jun 20, 2018

bsDatepicker has a property [minDate] and [maxDate], so you set those to "today" and inside your components constructor you do:

component.ts

today=new Date();

component.html

<input ... bsDatepicker ... [minDate]="today" [maxDate]="today" ... >

Anyway, having a datepicker when you don't really allow the user to select a date other than today makes no sense, you might as well default it to "today".