mat-datepicker 上的多种日期输入格式 [英] Multiple dateInput formats on mat-datepicker
问题描述
我正在创建两个 mat-datepicker,一个格式为MM/YYYY",另一个格式为DD/MM/YYYY",但我无法在模块中配置这两种格式.
I'm creating two mat-datepickers, one with the format "MM/YYYY" and another with the format "DD/MM/YYYY",but i can't configure both formats in the module.
我尝试将 MM/YYYY 的设置放在一个模块中,并将 DD/MM/YYYY 的设置放在应用程序模块中.
I tried to put in one module the settings for MM/YYYY and in the app module the settings for DD/MM/YYYY.
代码 1:
export const MY_FORMATS = {
parse: {
dateInput: 'MM/YYYY',
},
display: {
dateInput: 'MM/YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
},
...
providers: [{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS}]
};
代码 2:
export const MY_FORMATS = {
parse: {
dateInput: 'DD/MM/YYYY',
},
display: {
dateInput: 'DD/MM/YYYY',
monthYearLabel: 'DD MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'DD MMMM YYYY',
},
};
...
providers: [{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS}]
})
如果我在设置中使用 DD/MM/YYYY 格式,所有日期显示为 DD/MM/YYYY,如果我不使用,所有日期显示为 MM/YYYY.我该怎么做才能将一个日期显示为 MM/YYYY 而另一个日期显示为 DD/MM/YYYY?
If i use the DD/MM/YYYY format in the settings,all dates show as DD/MM/YYYY,if i don't use,all dates show as MM/YYYY. What should i do to show one date as MM/YYYY and another as DD/MM/YYYY?
推荐答案
你读过这个吗?https://medium.com/@kristinahertmann/多语言日期格式与角度材料b8598415d117
可以在此处找到此示例的 stackblitz.
Working stackblitz for this example can be found HERE.
这篇关于mat-datepicker 上的多种日期输入格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!