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.

相关内容

热门资讯

透视好友房!xpoker辅助怎... 透视好友房!xpoker辅助怎么用(透视)好像真的是有挂(详细辅助专业教程)1、任何ai辅助神器的玩...
一分钟了解!aapoker真的... 一分钟了解!aapoker真的假的,aapoker透视脚本下载,扑克教程(有挂技巧);原来确实真的有...
透视挂透视!wepoker私人... 透视挂透视!wepoker私人局透视方法(透视)切实是有挂(详细辅助黑科技教程);透视挂透视!wep...
玩家必知教程!wepoker私... 玩家必知教程!wepoker私人辅助器,哈糖大菠萝有没有挂,曝光教程(有挂透视)是一款可以让一直输的...
透视黑科技!wepoker破解... 透视黑科技!wepoker破解器有用吗(透视)其实真的是有挂(详细辅助微扑克教程)1、全新机制【软件...
科普分享!hhpoker为什么... 科普分享!hhpoker为什么一直输,hhpoker德州牛仔视频,详细教程(有挂神器);大神普及一款...
透视辅助!wepoker透视最... 透视辅助!wepoker透视最简单三个步骤(透视)其实是有挂(详细辅助AI教程)1、该软件可以轻松地...
必看攻略!拱趴大菠萝作弊方法,... 必看攻略!拱趴大菠萝作弊方法,拱趴大菠萝万能辅助器,科技教程(有挂方法);拱趴大菠萝万能辅助器软件透...
透视教学!aapoker公共底... 透视教学!aapoker公共底牌(透视)一直真的有挂(详细辅助教你攻略)透视教学!aapoker公共...
推荐十款!hhpoker底牌透... 推荐十款!hhpoker底牌透视脚本,智星菠萝辅助,2025版教程(有挂攻略);原来确实真的有挂(需...