在这篇文章中,我们将带领您了解angular–MAT_DATE_FORMATS字段的定义/含义的全貌,包括angulardatepipe的相关情况。同时,我们还将为您介绍有关angular–如何为da
在这篇文章中,我们将带领您了解angular – MAT_DATE_FORMATS字段的定义/含义的全貌,包括angular datepipe的相关情况。同时,我们还将为您介绍有关angular – 如何为datepicker实现MD_DATE_FORMATS?、angularjs datetime formate、angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母、angularjs – nggrid单元格模板中的ui-date-format的知识,以帮助您更好地理解这个主题。
本文目录一览:- angular – MAT_DATE_FORMATS字段的定义/含义(angular datepipe)
- angular – 如何为datepicker实现MD_DATE_FORMATS?
- angularjs datetime formate
- angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母
- angularjs – nggrid单元格模板中的ui-date-format
angular – MAT_DATE_FORMATS字段的定义/含义(angular datepipe)
export const MY_FORMATS = {
解析:{
dateInput:’LL’,
},
显示:{
dateInput:’LL’,
monthYearLabel:’MMM YYYY’,
dateA11yLabel:’LL’,
monthYeara11yLabel:’MMMM YYYY’,
};
我找不到像dateA11yLabel这样的字段将在何处以及如何发挥作用.我能想到的是display.dateInput用于在日历和display上显示所选日期.monthYearLabel用于年份选择器的选择下拉列表.
>其他领域在哪里使用?
>编写自定义MAT_DATE_FORMATS时,必须定义所有
字段?
解决方法
在这里 https://material.angular.io/components/datepicker/overview#accessibility
根据我认为这些格式用于在可访问性模式时显示datepicker.
angular – 如何为datepicker实现MD_DATE_FORMATS?
providers: [ {provide: DateAdapter,useValue: NativeDateAdapter },{provide: MD_DATE_FORMATS,useValue: MY_DATE_FORMATS },],
当我使用默认实现时:
export const MD_NATIVE_DATE_FORMATS: MdDateFormats = { parse: { dateInput: null,},display: { dateInput: {year: 'numeric',month: 'numeric',day: 'numeric'},monthYearLabel: {year: 'numeric',month: 'short'},dateA11yLabel: {year: 'numeric',month: 'long',monthYeara11yLabel: {year: 'numeric',month: 'long'},} };
我收到日期输入为空的错误.
但它到底是什么类型的?文档说任何.
如果我尝试放置一些虚拟函数,我会收到错误:_dateAdapter.parse不是函数.
function dateinput() { return 'ddd'; } const MY_DATE_FORMATS: MdDateFormats = Object.assign({},MD_NATIVE_DATE_FORMATS,{parse: dateInput });
如何使其工作?
export class OurDateAdapter extends NativeDateAdapter { parse(value: any): Date | null { if ((typeof value === 'string') && (value.indexOf('/') > -1)) { const str = value.split('/'); return new Date(Number(str[2]),Number(str[1])-1,Number(str[0]),12); } const timestamp = typeof value === 'number' ? value : Date.parse(value); return isNaN(timestamp) ? null : new Date(timestamp); } }
这可以是您的任何TS文件,只需要在组件的模块中使用日期选择器提供:
providers: [ {provide: DateAdapter,useClass: OurDateAdapter} ]
在组件中,您需要在构造函数中使用它:
constructor(private dateAdapter: DateAdapter<Date>) { this.dateAdapter.setLocale('en-GB'); }
可以在这里收集语言环境列表,plunkr示例使用葡萄牙语,我的是英国英语.
http://www.i18nguy.com/unicode/language-identifiers.html
MariusR,鞠躬,为什么官方文档不能有这个?
angularjs datetime formate
<table><tr>
<td><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49