Angular Material 6 中的 CustomeDateAdapter

编程入门 行业动态 更新时间:2024-10-28 18:26:24
本文介绍了Angular Material 6 中的 CustomeDateAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I have implemented a CustomDateAdapter as described here: https://medium/@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;

似乎平台未定义.

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

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 13:56:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1004812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Angular   Material   CustomeDateAdapter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!