1

我一直试图在我的 ngb-datepicker 中禁用周末。我还没有得到想要的输出。请看我的代码:

<ngb-datepicker #dp  [displayMonths]="1" [dayTemplate]="t"
      [minDate]="{year: 2018, month: 12, day: 1}"
      [maxDate]="{year: 2018, month: 12, day: 31}" 
      [markDisabled]="isDisabled">
    </ngb-datepicker>

        <ng-template #t let-date="date" let-focused="focused">
          <span class="custom-day" (click)="onDateSelection($event,date)"
                [class.focused]="focused"
                [class.range]="isFrom(date) || isTo(date) || isInside(date) || isHovered(date)"
                [class.faded]="isHovered(date) || isInside(date)"
                [class.selected]="isDateSelected(date)"
                [class.halfDay]="chkLeaveType(date,'half')"
                [class.fullDay]="chkLeaveType(date,'full')"
                [class.holiDay]="chkLeaveType(date,'holiDay')"
                (mouseenter)="hoveredDate = date"
                (mouseleave)="hoveredDate = null">
            {{ date.day }}
          </span>
        </ng-template>


     isDisabled(date: NgbDateStruct) {
        const d = new Date(date.year, date.month - 1, date.day);
        console.log(d.getDay() === 0);
        return  d.getDay() === 0 || d.getDay() === 6;
      }

isDisabled函数正在执行并返回适当的值,但我在日历中看不到禁用的效果。谁能告诉我我的代码有什么问题?提前致谢

4

1 回答 1

0

只需将属性“禁用”添加到标签中。不需要值。像这样:

<ngb-datepicker #dp  [displayMonths]="1" [dayTemplate]="t"
  [minDate]="{year: 2018, month: 12, day: 1}"
  [maxDate]="{year: 2018, month: 12, day: 31}" 
  disabled ></ngb-datepicker>
于 2021-06-16T19:16:16.677 回答