Angular 4日期选择器-如何限制未来和过去的日子 [英] Angular 4 Date-Picker - How to restrict Future and Past Days

查看:161
本文介绍了Angular 4日期选择器-如何限制未来和过去的日子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Angular 4 Date-Picker限制未来和过去的日子.我只想仅启用Current Date [today].我该如何解决.

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

这是我的模板:

<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",并在组件构造函数中执行以下操作:

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

component.ts

component.ts

today=new Date();

component.html

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

这篇关于Angular 4日期选择器-如何限制未来和过去的日子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆