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.

相关内容

热门资讯

必赢教程!wepoke透明黑科... 《必赢教程!wepoke透明黑科技(wepoke有挂)we辅助poker(其实真的有挂)》 we辅助...
德州之星辅助!德扑ai决策软件... 德州之星辅助!德扑ai决策软件,德州wpk果然有挂(详细外 挂教程)是一款可以让一直输的玩家,快速成...
wpk辅助挂!wpK本来真的有... wpk辅助挂!wpK本来真的有挂,wpK果然真的有挂,必赢方法(有挂解密)1、超多福利:超高返利,海...
wepower有外 挂!we-... 1、wepower有外 挂!we-poke有挂(透视辅助)wePoke(一贯真的有挂);详细教程。2...
德扑之星有作弊!德扑人工智能,... 德扑之星有作弊!德扑人工智能,德扑线上其实存在有挂(详细有猫腻教程)1、下载好德扑之星有作弊辅助软件...
攻略教程!wepoke透明真的... 攻略教程!wepoke透明真的(wepokeai代打)wepOke(都是真的有挂);1分钟了解详细教...
wpk德州透视辅助!wpk辅助... wpk德州透视辅助!wpk辅助器小程序,wPK原来真的有挂,详细教程,(有挂技巧)在进入wpk辅助挂...
德扑之星猫腻!德扑计算软件,w... 德扑之星猫腻!德扑计算软件,wepower德州都是真的是有挂(详细数据软件教程)1、金币登录送、破产...
细节方法!wepoke人有挂(... 细节方法!wepoke人有挂(wepoke计算辅助)wepoKe(就是真的有挂)1、很好的工具软件,...
wpk透视辅助测试!wpK一贯... wpk透视辅助测试!wpK一贯真的有挂,wpK的确真的有挂,介绍教程(有挂介绍);1、进入到wpk黑...