Angular 版本:6
库:ngbbootstrap
库参考链接:
https ://ng-bootstrap.github.io/#/components/datepicker/examples
https://ng-bootstrap.github.io/#/components/datepicker/api
使用上述库显示特定日期,我需要启用日期选择器的月份导航,但禁用日期的选择(单击)。
以下是我呈现日期选择器的代码,其中 in<ng-template>
用于自定义日视图:
<ngb-datepicker #datepicker [(ngModel)]="model" (navigate)="date = $event.next" (select)="onDateSelect($event)"
(ngModelChange)="onModelChange($event)" [dayTemplate]="templete" [disabled]="disabled" [firstDayOfWeek]="0"></ngb-datepicker>
<ng-template #templete let-date="date">
<span *ngIf="!showFixedDates" class="custom-day" [class.range]="isFrom(date) || isTo(date) || isInside(date) || isHovered(date)"
[class.faded]="isHovered(date) || isInside(date) || (isContains(date) && showFixedDates)"
[class.focused]="focused && showFixedDates" [class.hidden]="isPrevious(date) || isAfter6Months(date)"
[class.previousRangeExtremes]="isPrevious(date) && ( isFrom(date) || isTo(date))" [class.previousRange]="isPrevious(date) && isInside(date)"
(mouseenter)="hoveredDate = date" (mouseleave)="hoveredDate = null">
{{ date.day }}
</span>
<span *ngIf="showFixedDates" class="custom-day" [class.focused]="focused"
[class.range]="isContains(date)" (mouseenter)="hoveredDate = date" (mouseleave)="hoveredDate = null">
{{ date.day }}
</span>
</ng-template>
在这方面的一些帮助会很棒!