如何使用角度6在日期时间选择器中禁用月份

时间:2019-05-20 12:06:33

标签: bootstrap-4 angular6

在我的网页中,我有2个字段“装运月从”和“装运月至”。例如,如果用户在第一个日期选择器中选择2月,则月份列表应仅从2月开始。一月需要禁用。我已经尝试过minDate,但minDate仅适用于“日期选择”。但是我需要限制月份。请帮帮我

html

        <div class="form-group col-xs-12 col-sm-12 col-md-3 col-lg-3">
                        <label for="createDateFrom" class="control-label">CreateDate From</label>
                            <div class="input-group datepicker-input">
                                <input labelForId="createDateFrom" placeholder="ํYYYY/MM/DD" [(ngModel)]="searchInquiryForm.createDateFrom" (ngModelChange)="changeDateFrom(searchInquiryForm.createDateFrom)" [bsConfig]="{ containerClass: 'theme-red' ,dateInputFormat: 'YYYY/MM/DD', showWeekNumbers: false }" 
                                type="text" class="form-control" #dp="bsDatepicker" name="createDateFrom" bsDatepicker >
                                <button class="btn btn-secondary" (click)="dp.toggle()" [attr.aria-expanded]="dp.isOpen">
                                    <span class="fa fa-calendar"></span>
                                </button>
                            </div>
                    </div>
                    <div class="form-group col-xs-12 col-sm-12 col-md-3 col-lg-3">
                        <label for="createDateTo" class="control-label">CreateDate to</label>
                            <div class="input-group datepicker-input">
                                <input  [minDate]="minDate" labelForId="createDateTo" placeholder="YYYY/MM/DD" [(ngModel)]="searchInquiryForm.createDateTo" (ngModelChange)="changeDateTo(searchInquiryForm.createDateTo)" [bsConfig]="{ containerClass: 'theme-red' ,dateInputFormat: 'YYYY/MM/DD', showWeekNumbers: false }" 
                                type="text" class="form-control" #dp1="bsDatepicker" name="createDateTo" bsDatepicker >
                                <button class="btn btn-secondary" (click)="dp1.toggle()" [attr.aria-expanded]="dp.isOpen">
                                    <span class="fa fa-calendar"></span>
                                </button>
                            </div>
                    </div>

ts

  changeDateFrom(date){
console.log(date);
this.minDate = date;
if(date){
  this.searchInquiryForm.createDateFrom  =  this.datePipe.transform(date, 'yyyy/MM/dd');
  if(new Date(this.searchInquiryForm.createDateFrom) >= new Date(this.searchInquiryForm.createDateTo)){
     this.searchInquiryForm.createDateTo = null;
  }
}

}

     changeDateTo(date){
    if(date){
    this.searchInquiryForm.createDateTo =  this.datePipe.transform(date, 
    'yyyy/MM/dd');
    }
 }

此代码对于日期有效,但我需要限制月份。

0 个答案:

没有答案