Angular 4 Date-Picker - 如何限制未来和过去的日子

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

我想使用 Angular 4 日期-Picker.I 来限制未来和过去的日子,只想启用当前日期[今天] only.How 我可以解决这个问题吗?

谁能有想法...???

这是我的模板:

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

bsDatepicker 有一个 属性 [minDate][maxDate],因此您将它们设置为 "today" 并在您的组件构造函数中执行:

component.ts

today=new Date();

component.html

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

无论如何,当您实际上不允许用户 select 除今天以外的日期时使用日期选择器是没有意义的,您最好将其默认为 "today".

与上面提到的类似,但在 angular 中根据: https://material.angular.io/components/datepicker/api

component.ts

today = new Date()

component.html

<input matInput [min]="today" [max]="today">