angular - Angular 7 Mat datepicker - 如何将月份名称从短更改为长:
解决方案
据我所知,您可以使用日期选择器组件配置的唯一格式是:https ://material.angular.io/components/datepicker/overview#accessibility
@NgModule({
imports: [MatDatepickerModule, MomentDateModule],
providers: [
{
provide: MAT_DATE_FORMATS,
useValue: {
parse: {
dateInput: ['l', 'LL'],
},
display: {
dateInput: 'L',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
},
},
},
],
})
export class MyApp {}
如果您想知道这些来自哪里或语法是如何完成的,请查看此链接:https ://momentjs.com/docs/#/displaying/format/
如果您仍然想尝试更改它,您可以尝试从 moment.js 覆盖monthShort,这是使用此组件工作的库:
moment.updateLocale('en', {
months : [
"January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"
]
});
考虑到您在上面看到的这个标签适用于语言环境
constructor(@Optional() @Inject(MAT_DATE_LOCALE) dateLocale: string) {
super();
this.setLocale(dateLocale || moment.locale());
}
setLocale(locale: string) {
super.setLocale(locale);
let momentLocaleData = moment.localeData(locale);
this._localeData = {
firstDayOfWeek: momentLocaleData.firstDayOfWeek(),
longMonths: momentLocaleData.months(),
shortMonths: momentLocaleData.monthsShort(),
dates: range(31, (i) => this.createDate(2017, 0, i + 1).format('D')),
longDaysOfWeek: momentLocaleData.weekdays(),
shortDaysOfWeek: momentLocaleData.weekdaysShort(),
narrowDaysOfWeek: momentLocaleData.weekdaysMin(),
};
}
推荐阅读
- sorting - 在第二行数据的 awk 中使用 sort 和 uniq -c
- javascript - 我想要 Sequelize 形式的这个查询
- mui-datatable - mui 数据表列宽选项不可用
- javascript - JavaScript中数组中的特定元素?
- flutter - Flutter 在使用 Speech_recognition 和 workmanager 时中断执行
- c - 优化文件写入 C
- xtermjs - Xterm.js 在 macOS 中的奇怪行为
- ios - 颤振:错误:找不到吸气剂:“暂停”。案例 AppLifecycleState.suspending
- plugins - 我们如何编写包含客户端和服务器端更改的 Rundeck 插件?
- android - 有没有办法在这做 2000 else if 语句?