【问题标题】:How to disable future dates in bsdatePicker如何在 bsdatePicker 中禁用未来日期
【发布时间】:2019-05-29 19:06:32
【问题描述】:

我在我的 Angular 项目中使用 bsdatepicker,我想禁用该 datePicker 中的所有未来日期以进行 DOB 选择

import { Component } from '@angular/core';

@Component({
  selector: 'demo-datepicker-datesdisabled',
  templateUrl: './disable-dates.html'
})
export class DemoDatepickerDatesDisabledComponent {
  disabledDates = [
    new Date('2019-02-05'),
    new Date('2019-02-09')
  ];
}



<div class="row">
  <div class="col-xs-12 col-12 col-md-4 form-group">
    <input type="text"
           placeholder="Datepicker"
           class="form-control"
           bsDatepicker
           [datesDisabled]="disabledDates">
  </div>
  <div class="col-xs-12 col-12 col-md-4 form-group">
    <input type="text"
           placeholder="Daterangepicker"
           class="form-control"
           bsDaterangepicker
           [datesDisabled]="disabledDates">
  </div>
</div>

上面的代码正在运行,但我想禁用未来的 N 个日期

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    将[maxDate] 设置为今天。

    <input type="text"
               placeholder="Daterangepicker"
               class="form-control"
               bsDaterangepicker
               [datesDisabled]="disabledDates"
               [maxDate]="today"
    >
    
    public today = new Date();
    

    【讨论】:

      猜你喜欢
      • 2018-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      相关资源
      最近更新 更多