我正在尝试从material2为闪亮的新datepicker实现我自己的日期格式.根据文档,我必须提供我的MD_DATE_FORMATS版本:
providers: [
{provide: DateAdapter, useValue: NativeDateAdapter },
{provide: MD_DATE_FORMATS, useValue: MY_DATE_FORMATS },
],
Run Code Online (Sandbox Code Playgroud)
当我使用默认实现时:
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', day: 'numeric'},
monthYearA11yLabel: {year: 'numeric', month: 'long'},
}
};
Run Code Online (Sandbox Code Playgroud)
我收到日期输入为空的错误.但它到底是什么类型的?文档说任何.
如果我尝试放一些虚拟函数,我会得到错误: _dateAdapter.parse is not a function.
function dateInput() {
return 'ddd';
}
const MY_DATE_FORMATS: MdDateFormats = Object.assign({}, MD_NATIVE_DATE_FORMATS, {parse: dateInput });
Run Code Online (Sandbox Code Playgroud)
如何使它工作?