Angular 5的ng-bootstrap日期选择器禁用特定日期的数组
创始人
2024-10-15 22:31:10
0

要在Angular 5的ng-bootstrap日期选择器中禁用特定日期,您可以使用ng-bootstrap的CustomDatepickerDayViewComponent来自定义日期选择器的外观和行为。以下是一个示例代码,演示如何禁用特定日期的数组:

  1. 创建一个新的组件custom-datepicker-day-view.component.ts:
import { Component, Input } from '@angular/core';
import { NgbDatepickerDayView } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-custom-datepicker-day-view',
  template: `
    
      
{{ date.day }}
`, styles: [ ` .disabled { background-color: #eee; color: #999; } ` ] }) export class CustomDatepickerDayViewComponent extends NgbDatepickerDayView { @Input() disabledDates: Date[]; isDisabled(date: NgbDateStruct): boolean { const d = new Date(date.year, date.month - 1, date.day); return this.disabledDates.some(disabledDate => { return d.getTime() === disabledDate.getTime(); }); } }
  1. 在需要使用日期选择器的组件中,例如app.component.ts,添加以下代码:
import { Component } from '@angular/core';
import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-root',
  template: `
    

ng-bootstrap Datepicker

`, styles: [` .container { margin-top: 50px; } `] }) export class AppComponent { customDayView = CustomDatepickerDayViewComponent; disabledDates: Date[] = [ new Date(2021, 0, 1), // January 1, 2021 new Date(2021, 0, 15) // January 15, 2021 ]; }
  1. 在app.module.ts中,将CustomDatepickerDayViewComponent添加到NgModule的declarations数组中:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

import { AppComponent } from './app.component';
import { CustomDatepickerDayViewComponent } from './custom-datepicker-day-view.component';

@NgModule({
  declarations: [
    AppComponent,
    CustomDatepickerDayViewComponent
  ],
  imports: [
    BrowserModule,
    NgbModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

这样,您就可以使用自定义日期选择器组件,并在disabledDates数组中指定要禁用的特定日期。

相关内容

热门资讯

总算了解!德州圈脚本,hhpo... 1、总算了解!德州圈脚本,hhpoker德州机器人,曝光教程(有挂透明)。2、hhpoker德州机器...
重大来袭!德州透视是真的假的,... 重大来袭!德州透视是真的假的,hhpoker可以开挂吗,解说技巧(有挂透视)1、玩家可以在德州透视是...
发现一款!impoker辅助,... 发现一款!impoker辅助,来玩德州破解器,微扑克教程(有挂教程)是由北京得来玩德州破解器黑科技有...
指导大家!hhpoker有没有... 指导大家!hhpoker有没有作弊挂,agpoker辅助,wpk教程(有挂教程)1、不需要AI权限,...
玩家必知教程!德普之星透视辅助... 玩家必知教程!德普之星透视辅助软件激活码,wepoker透视脚本,教你教程(有挂教程);玩家必备必赢...
每日必看!wepoker透视底... 每日必看!wepoker透视底牌脚本,hhpoker底牌透视脚本,安装教程(有挂技巧);《WPK辅助...
玩家必看教程!德州局hhpok... 玩家必看教程!德州局hhpoker,WePoKer辅助器,黑科技教程(有挂透明)1、点击下载安装,微...
技巧知识分享!wepoker有... 您好,wepoker有没有透视方法这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302...
盘点十款!大菠萝辅助器,hhp... 自定义hhpoker辅助软件下载系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
最新通报!wepoker怎么设... 最新通报!wepoker怎么设置透视,德扑圈有透视吗,细节揭秘(有挂软件);实战中需综合运用上述技巧...