作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经实现了一个 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/
我已经实现了一个 CustomDateAdapter,如下所述:https://medium.com/@esanjiv/working-with-custom-dateadapter-for-angu
我是一名优秀的程序员,十分优秀!