如何禁用NG-ZORO中nz-calendar组件的单元格点击事件?
禁用NG-ZORO nz-calendar单元格点击功能
这里提供两种实用方案,根据你的需求选择:
方案1:阻止点击事件冒泡 + 禁用指针事件
这种方式仅阻止日历单元格的默认点击行为(比如切换选中日期、切换月/年视图),不影响你自定义单元格内容的交互(如果有的话)。
修改后的模板代码:
<nz-calendar [(ngModel)]="date" [(nzMode)]="mode" > <div *nzDateCell="let date" class="date-cell" (click)="$event.stopPropagation()" (mousedown)="$event.stopPropagation()"> <ng-container *ngIf="getCellWithData(date);let cell"> {{fillCellWithData(cell)}} </ng-container> </div> </nz-calendar>
添加CSS样式:
.date-cell { pointer-events: none; } /* 若自定义内容需要保留交互,单独开启 */ .date-cell .your-custom-interactive-element { pointer-events: auto; }
方案2:利用nzDisabledDate全局禁用日期选择
如果需要完全禁用所有日期的选择逻辑(包括点击选中、切换视图),可以通过nzDisabledDate属性返回true,直接让所有日期处于禁用状态:
<nz-calendar [(ngModel)]="date" [(nzMode)]="mode" [nzDisabledDate]="() => true" > <div *nzDateCell="let date" class="date-cell"> <ng-container *ngIf="getCellWithData(date);let cell"> {{fillCellWithData(cell)}} </ng-container> </div> </nz-calendar>
内容的提问来源于stack exchange,提问作者Rezo Kobaidze
相关产品推荐
相关产品推荐

