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数组中指定要禁用的特定日期。

相关内容

热门资讯

wepoker透视辅助!wep... wepoker透视辅助!wepoker辅助软件价格(透视)器-确实了解存在有挂在进入wepoker辅...
透视专业!wpk有辅助器吗(透... 透视专业!wpk有辅助器吗(透视)悦扑克脚本,教程方案(了解有挂)-哔哩哔哩1、wpk有辅助器吗辅助...
pokemmo手机脚本辅助器!... pokemmo手机脚本辅助器!xpoker辅助怎么用(透视)技巧-总是了解有挂1、pokemmo手机...
透视辅助!hhpoker开挂靠... 透视辅助!hhpoker开挂靠谱吗(透视)wepoker透视功能下载,教程妙计(有挂技巧)-哔哩哔哩...
红龙poker辅助平台!wep... 红龙poker辅助平台!wepoker俱乐部辅助器(透视)插件-真是普及是真的挂1、wepoker俱...
透视科普!pokemmo辅助器... 透视科普!pokemmo辅助器手机版下载(透视)智星德州插件2024最新版,教程手册(有挂助手)-哔...
pokemmo脚本!破解辅助插... pokemmo脚本!破解辅助插件wepoker(透视)工具-确实解谜真的是有挂破解辅助插件wepok...
透视了解!wepoker有透视... 透视了解!wepoker有透视功能吗(透视)wepoker黑侠辅助器,教程秘籍(有挂技巧)-哔哩哔哩...
wepoker开辅助能查到吗!... wepoker开辅助能查到吗!wepoker究竟有没有透视(透视)插件-切实开挂是有挂1、游戏颠覆性...
透视必备!聚星ai辅助工具激活... 透视必备!聚星ai辅助工具激活码(透视)xpoker辅助,教程妙计(有挂教学)-哔哩哔哩1、完成聚星...