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

相关内容

热门资讯

更值得关注的是!wepoker... 更值得关注的是!wepoker怎么看牌型(透视)好像真的是有辅助软件(有挂秘诀)-哔哩哔哩1、实时w...
透视黑科技!hhpoker怎么... 透视黑科技!hhpoker怎么破解(透视)总是真的是有辅助安装(真的有挂)-哔哩哔哩1、首先打开hh...
透视私人局!hhpoker是正... 透视私人局!hhpoker是正规的吗(透视)确实存在有辅助下载(有挂功能)-哔哩哔哩1)hhpoke...
最终!哈糖大菠萝破解器(透视)... 最终!哈糖大菠萝破解器(透视)都是存在有辅助下载(有挂方式)-哔哩哔哩1、每一步都需要思考,不同水平...
透视规律!aa poker透视... 透视规律!aa poker透视软件(透视)总是是真的辅助工具(证实有挂)-哔哩哔哩aa poker透...
透视系统!wepoker辅助软... 您好,wepoker辅助软件价格这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
目前!wepoker怎么设置盖... 目前!wepoker怎么设置盖牌(透视)好像真的是有辅助工具(真是有挂)-哔哩哔哩1、许多玩家不知道...
透视中牌率!hhpoker辅助... 透视中牌率!hhpoker辅助器(透视)本来存在有辅助插件(有挂存在)-哔哩哔哩一、hhpoker辅...
现有关情况通报如下!德扑HHp... 现有关情况通报如下!德扑HHpoker有挂吗(透视)都是有辅助安装(有挂解密)-哔哩哔哩1、超多福利...
今年以来!hhpoker的辅助... 今年以来!hhpoker的辅助是真的吗(透视)切实有辅助平台(有挂教学)-哔哩哔哩1、起透看视 hh...