Angular Material 6中的CustomeDateAdapter [英] CustomeDateAdapter in Angular Material 6
问题描述
我已经实现了CustomDateAdapter,如下所述: https://medium.com/@esanjiv/working-with-custom-dateadapter-for-angular-material-2-datepicker-76d4446277dc
I have implemented a CustomDateAdapter as described here: https://medium.com/@esanjiv/working-with-custom-dateadapter-for-angular-material-2-datepicker-76d4446277dc
现在,我正在进行Angular Material 6迁移,并且出现以下错误
Now, I am doing the Angular Material 6 migration and I get the following error
core.js:1598 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'TRIDENT' of undefined
TypeError: Cannot read property 'TRIDENT' of undefined
at CustomDateAdapter.NativeDateAdapter [as constructor] (core.es5.js:792)
at new CustomDateAdapter (custom-date-adapter.ts:21)
at _createClass (core.js:9262)
...
core.es5.js第792行是这样的:
core.es5.js line 792 is this:
_this.useUtcForDisplay = !platform.TRIDENT;
似乎平台未定义.
我注意到NativeDateAdapter的构造函数已在Material 6中进行了更改,它也需要一个平台作为输入.
I noticed that the constructor of the NativeDateAdapter has changed in Material 6, it also requires a platform as input.
constructor(matDateLocale: string, platform: Platform);
我缺少什么?如何在Angular Material 6中实现CustomDateAdapter?
What I am missing? How can I implement a CustomDateAdapter in Angular Material 6?
推荐答案
我遇到了同样的问题.这是我的解决方法.
I had the same problem. Here is my fix.
// in your shared or main.module.ts
// … other imports
import {Platform, PlatformModule} from '@angular/cdk/platform';
@NgModule({
imports: [
// …
PlatformModule
],
exports: [
// …
PlatformModule
],
providers: [
{provide: DateAdapter, useClass: YourCustomDateAdapter, deps: [MAT_DATE_LOCALE, Platform]},
]
});
export class SharedModule {
}
并且您没有覆盖YourCustomDateAdapter
的构造函数.
And you haven't override the YourCustomDateAdapter
's constructor.
这篇关于Angular Material 6中的CustomeDateAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!