gpt4 book ai didi

angular - Angular Material 6 中的 CustomeDateAdapter

转载 作者:太空狗 更新时间:2023-10-29 17:44:16 25 4
gpt4 key购买 nike

我已经实现了一个 CustomDateAdapter,如下所述:https://medium.com/@esanjiv/working-with-custom-dateadapter-for-angular-material-2-datepicker-76d4446277dc

现在,我正在执行 Angular Material 6 迁移,但出现以下错误

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 行是这样的:

_this.useUtcForDisplay = !platform.TRIDENT;

看来平台未定义。

我注意到 NativeDateAdapter 的构造函数在 Material 6 中发生了变化,它还需要一个平台作为输入。

constructor(matDateLocale: string, platform: Platform);

我错过了什么?如何在 Angular Material 6 中实现 CustomDateAdapter?

最佳答案

我遇到了同样的问题。这是我的解决方法。

// 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 的构造函数。

关于angular - Angular Material 6 中的 CustomeDateAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50608655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com