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.

相关内容

热门资讯

透视透视"poker... 透视透视"pokernow辅助工具"详细辅助揭秘教程(免费脚本弱密码软件);人气非常高,ai更新快且...
透视黑科技"wepo... 1、透视黑科技"wepoker模拟器哪个"详细辅助靠谱教程(底牌透视脚本辅助)。2、wepoker模...
透视教程"wepok... 1、透视教程"wepoker怎么获得好牌"详细辅助技巧教程(辅助器下载技巧)(UU poker、we...
透视计算"德普之星怎... 这是一款非常优秀的德普之星怎么开辅助 ia辅助检测软件,能够让你了解到德普之星怎么开辅助中牌率当中全...
透视能赢"红龙pok... 透视能赢"红龙poker作弊指令"详细辅助细节揭秘(好友局透视技巧);支持多人共享记分板与复盘,通过...
透视最新"德扑HHp... 透视最新"德扑HHpoker有挂吗"详细辅助力荐教程(辅助软件视频辅助)是一款可以让一直输的玩家,快...
透视玄学"wepok... 透视玄学"wepoker插件辅助"详细辅助技巧教程(破解游戏盒子透视)1、很好的工具软件,可以解锁游...
透视挂透视"wepo... 透视挂透视"wepoker私人局辅助挂"详细辅助透牌教程(轻量版透视系统技巧)科技教程也叫必备教程,...
透视透视挂"hhpo... 透视透视挂"hhpoker透视脚本"详细辅助扑克教程(有插件软件);玩家必备必赢加哟《1367043...
透视最新"拱趴大菠萝... 透视最新"拱趴大菠萝作弊方法"详细辅助2025新版教程(靠谱透视)准备好在拱趴大菠萝作弊方法ia的高...