AngularmatDatepicker禁用日期转型
创始人
2024-10-28 07:01:37
0次

要禁用matDatepicker中的日期转型,可以使用DateAdapter中的format方法。可以扩展NativeDateAdapter并覆盖format()。以下是一个示例:

import { NativeDateAdapter} from '@angular/material/core';
import { MatDateFormats } from '@angular/material/core';

export class MyDateAdapter extends NativeDateAdapter {
  format(date: Date, displayFormat: Object): string {
    if (displayFormat === 'input') {
      const day = date.getDate();
      const month = date.getMonth() + 1;
      const year = date.getFullYear();
      return `${year}-${month}-${day}`;
    }
    return date.toDateString();
  }
}

export const MY_DATE_FORMATS: MatDateFormats = {
  parse: {
    //不需要设置解析格式;
    dateInput: null,
  },
  display: {
    dateInput: 'input',
    monthYearLabel: 'MM/YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
  },
};

//添加到模块之后,可以使用它对matDatepicker的所有日期选项卡进行禁用。MatDatePicker中有一个“dateClass“选项,它可以使用matDatepicker的日历组件中的自定义函数来禁用特定日期。

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css'],
  providers: [
    { provide: DateAdapter, useClass: MyDateAdapter },
    { provide: MAT_DATE_FORMATS, useValue: MY_DATE_FORMATS },
  ],
})
export class MyComponent {}

//在模板上设置日期className样式来禁用它
template:
  
    
    
    
  

ts:
  dateClass() {
    return (date: Date): MatCalendarCellCssClasses => {
      const day = date.getDate();
      // Disable 1st of

相关内容

热门资讯

WPK官网透视挂阶段!wepo... WPK官网透视挂阶段!wepoker私局代打,红龙扑克ai多功能透视挂脚本1、wepoker私局代打...
WPK辅助辅助器窍要!we-p... WPK辅助辅助器窍要!we-poker靠谱吗,德州扑克ai多功能辅助器技巧一、we-poker靠谱吗...
WPK透视开挂技法!wepok... WPK透视开挂技法!wepoker透视底牌脚本,智星菠萝德州ai多功能开挂教程1、首先打开wepok...
WPK方法开挂项目!wepok... WPK方法开挂项目!wepoker破解游戏盒子,红龙PoKerai多功能开挂方法1.wepoker破...
WPK工具开挂窍要!wpk插件... WPK工具开挂窍要!wpk插件辅助,红龙PoKerai多功能开挂插件1、wpk插件辅助模拟器是什么优...
WPK购买透视挂秘籍!wepo... WPK购买透视挂秘籍!wepoker私人定制透视,AApokerai多功能透视挂app1、wepok...
WPK透视透视阶段!wepok... WPK透视透视阶段!wepoker辅助透视,智星菠萝德州ai多功能透视神器1、起透看视 wepoke...
WPK有透视辅助器步骤!wep... WPK有透视辅助器步骤!wepoker私人局有透视吗,智星菠萝德州ai多功能辅助器攻略1、这是跨平台...
WPK多开辅助器手筋!wepo... WPK多开辅助器手筋!wepoker辅助是真的假的,WPKai多功能辅助器攻略1、超多福利:超高返利...
WPK多开辅助法门!wepok... WPK多开辅助法门!wepoker插件辅助,aapokerai多功能辅助攻略wepoker插件辅助辅...