我一直在尝试在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
函数正在执行并返回适当的值,但是我在日历中看不到禁用的效果。
有人可以告诉我代码中的错误吗?预先感谢
答案 0 :(得分: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>