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

主宰稳场 提交于 2019-12-12 09:05:23

问题


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">

回答1:


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".



来源:https://stackoverflow.com/questions/50947730/angular-4-date-picker-how-to-restrict-future-and-past-days

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!