在日期选择器中限制多个日期

时间:2018-07-07 23:34:37

标签: html angular html5 typescript bootstrap-4

我有一个日历,我想禁用植物素日期,正在使用https://www.primefaces.org/primeng/#/calendar

在html中我有这个

<p-calendar formControlName="date"  [inline]="true" [disabledDates]="restictedBookingDates"  [minDate]="minimumDate" tabindex="0" readonlyInput="true">
                <ng-template pTemplate="date" let-date>
                    <span [ngStyle]="{backgroundColor: (date.day ==10) ? '#7cc67c' : 'inherit'}"   style="border-radius:50%">{{date.day}}</span>
                </ng-template>
            </p-calendar>

在我拥有的电脑中

 restictedBookingDates: Array<Date>; 

 ngOnInit() {
    const today = new Date();
    const invalidDate = new Date();
    invalidDate.setDate(today.getDate() - 1);
    this.restictedBookingDates = [today, invalidDate];
  }

这仅限制今天的日期,我希望能够限制多个日期,例如

var restictedBookingDates= ["7-15-2018", "7-23-2018", "7-23-2018"];

我需要更改我的代码以完成我想要的东西吗?

1 个答案:

答案 0 :(得分:1)

创建一个限制日期数组,如下所示:

restrictedBookingDates = [
    new Date(2018, 6, 23),
    new Date(2018, 6, 17)
];

这将限制7月23日至17日的预订。请注意,月份选项从零开始,所以6代表七月。

Here is a StackBlitz example

相关问题