AngularNg2日期选择器不会自动刷新禁用日期。
创始人
2024-10-28 16:30:22
0

首先,通过@ViewChild选择日期选择器组件。然后,定义一个名为disableDates的函数,该函数将返回一组要禁用的日期。在ngAfterViewInit生命周期钩子中,调用setAttribute()方法来更新组件中禁用的日期。最后,更新日期时,调用更新函数以刷新禁用的日期。示例代码如下:

import { Component, ViewChild, AfterViewInit } from '@angular/core'; import { Ng2BootstrapModule } from 'ng2-bootstrap'; import * as moment from 'moment';

@Component({ selector: 'app-datepicker', templateUrl: './datepicker.component.html' }) export class DatepickerComponent { @ViewChild('datepicker') datepicker;

// define function to return disabled dates disableDates(): any { let now = moment(); return { daysOfWeek: [0, 6], daysOfMonth: [1, 2, 3, 4, 5], dates: [now.add(1, 'M').add(2, 'd')] }; }

// update disable dates updateDisableDates(): void { let dates = this.disableDates(); this.datepicker.setAttribute('options', '{ "disable": ' + JSON.stringify(dates) + ' } '); }

// call update function when dates change onDateChange(): void { this.updateDisableDates(); }

// call update function when component initializes ngAfterViewInit(): void { this.updateDisableDates(); } }

请注意,moment.js库是在此示例中使用的日期库之一,仅供参考。actual example may use a different library or approach.

相关内容

热门资讯

总算了解!wepoker透视是... 总算了解!wepoker透视是真的吗,wepoker免费透视脚本,安装教程(有挂透视);致您一封信;...
最新通报!aapoker ai... 最新通报!aapoker ai插件,wepoker怎么设置房间,解密教程(有挂技巧);玩家必备必赢加...
必备攻略!werplan透视挂... 必备攻略!werplan透视挂,werplan透视挂,攻略教程(有挂软件);致您一封信;亲爱werp...
玩家交流!约局吧能不能开挂,约... 玩家交流!约局吧能不能开挂,约局吧如何查看是否有挂,AA德州教程(有挂技巧)科技教程也叫必备教程,这...
总算清楚!wepoker透视版... 总算清楚!wepoker透视版下载,wepoker祈福有用吗,规律教程(有挂教程);建议优先通过we...
2分钟细说!红龙poker辅助... 2分钟细说!红龙poker辅助,hhpoker有没有外挂,黑科技教程(有挂辅助);最新版2024是一...
我来教大家!wepoker辅助... 我来教大家!wepoker辅助透视,wepoker免费脚本咨询,新版2025教程(有挂教程);支持2...
最新通报!hhpoker有透视... 此外,数据分析德州(hhpoker有透视功能吗)辅助神器app还具备辅助透视行为开挂功能,通过对客户...
透视教学!hhpoker视频巡... 透视教学!hhpoker视频巡查真的假的(透视)本来真的有挂(详细辅助新2025版);1、透视辅助简...
透视线上!wepokerh5破... 透视线上!wepokerh5破解(透视)本来有挂(详细辅助分享教程)运辅助工具,进入游戏界面。进入辅...