typescript MAT_DATE_FORMATS 字段的定义/含义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49569854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:19:14  来源:igfitidea点击:

MAT_DATE_FORMATS definition/meaning of fields

angulartypescriptdatepickerangular-material2

提问by Abhishek Jha

Material example for customizing-the-parse-and-display-formatsfor date picker uses custom MAT_DATE_FORMATS

日期选择器的自定义解析和显示格式的材料示例使用自定义 MAT_DATE_FORMATS

export const MY_FORMATS = {
  parse: {
    dateInput: 'LL',
  },
  display: {
    dateInput: 'LL',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM YYYY',
  },
};

I could not find where and how these fields like dateA11yLabelwill come into play. What I could figure out was display.dateInputis used in displaying selected date on calendar and display.monthYearLabelis used in the select drop-down of year selector.

我找不到这些领域dateA11yLabel将在何处以及如何发挥作用。我能弄清楚的display.dateInput是用于在日历上显示所选日期并display.monthYearLabel用于年份选择器的选择下拉列表。

  1. Where are rest of the fields used?
  2. When writing custom MAT_DATE_FORMATS is it mandatory to define all fields?
  1. 其余的字段在哪里使用?
  2. 编写自定义 MAT_DATE_FORMATS 时是否必须定义所有字段?

回答by Mo Hamid

Well, I figured out the following:

好吧,我想出了以下几点:

datepicker

日期选择器

 parse: {

    dateInput: 'DD.MM.YYYY',
  }, 
  display: {

    dateInput: 'DD.MM.YYYY',
    monthYearLabel: 'MMM YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'MMMM-YYYY',
  },
  • with parse.dateInput: you can let the user enter any type of date with any format, and the date adapter will reformat it to the format you specify in this attribute

  • with display.dateInputyou can specify the input date format (marked with 1)

  • display.monthYearLabelyou can specify the area marked with 2

  • with parse.dateInput:您可以让用户以任何格式输入任何类型的日期,日期适配器会将其重新格式化为您在此属性中指定的格式

  • display.dateInput您可以指定输入的日期格式(标有1)

  • display.monthYearLabel您可以指定标有 2 的区域

unfortunately, I still don't know about the rest!

不幸的是,我仍然不知道其余的!

回答by Dmytro Bardai

A11Y - means accessibility. Look here https://material.angular.io/cdk/a11y/overviewand here https://material.angular.io/components/datepicker/overview#accessibility

A11Y - 表示可访问性。看这里https://material.angular.io/cdk/a11y/overview和这里https://material.angular.io/components/datepicker/overview#accessibility

According that I think these formats are used to display datepicker when accessibility mode on.

据此,我认为这些格式用于在无障碍模式下显示日期选择器。