primeNg日历无法禁用数组中的日期或突出显示当前日期

时间:2019-03-13 13:12:32

标签: angular angular-material primeng primeng-calendar

 {
      "currentTradeDate": "2019-03-12",
      "dateArray": [
        {
          "holidayDate": "2019-12-25"
        },
        {
          "holidayDate": "2019-11-28"
        },
        {
          "holidayDate": "2019-09-02"
        },
        {
          "holidayDate": "2019-07-04"
        },
        ]
   
<p-calendar placeholder="yyyy/mm/dd"
      dateFormat="yy-mm-dd" [(ngModel)]="value" [disabledDates]="invalidDates" [disabledDays]="[0,6]" name="value" [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" (ngModelChange)="selectDate($event)">
    


      <ng-template pTemplate="date" let-date>
        <span [ngStyle]="{backgroundColor: (date.day === currDay) ? 'yellow' : 'inherit'}">{{date.day}}</span>
    </ng-template>


    
    </p-calendar>

以上是我从api调用中得到的json响应。我将放假日期放在像invalidDates = [“ 2019-12-25”,“ 2019-11-28”,“ 2019-09-02”] ..这样的数组中,但是我无法在p-calendar ....我也无法在p-calendar中突出显示currentTradeDate吗?

invalidDates数组日期需要转换为date数组?还是什么?或者我应该使用除primeNg之外的其他datePicker。请提出建议。

1 个答案:

答案 0 :(得分:0)

您可以在您的组件中尝试这一点。

  let invalidDate = new Date();
  let today = new Date();
  invalidDate.setDate(today.getDate() - 1);
  this.invalidDates = [today,invalidDate];