角材料:MatDatepicker:找不到DateAdapter提供程序 [英] Angular material: MatDatepicker: No provider found for DateAdapter

查看:160
本文介绍了角材料:MatDatepicker:找不到DateAdapter提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Angular Material中使用Datepicker组件.这是我的HTML代码:

I'm trying to use the Datepicker component in Angular Material. Here is my HTML code:

<input matInput [matDatepicker]="picker" placeholder="Choose a date" disabled>
<mat-datepicker #picker disabled="false"></mat-datepicker>

但是,它对我不起作用,并且出现以下错误:

However, it's not working for me and I'm getting the following error:

错误:MatDatepicker:未找到DateAdapter的提供程序.

Error: MatDatepicker: No provider found for DateAdapter.

该错误消息告诉我,我需要导入MatNativeDateModule和MatDatepickerModule,但是我已经做到了.这是我下面来自app.module.ts的导入代码:

The error message tells me that I need to import MatNativeDateModule as well as MatDatepickerModule but I have done that. Here is my import code below from app.module.ts:

import {
    MatFormFieldModule,
    MatMenuModule,
    MatCheckboxModule,
    MatIconModule,
    MatDatepickerModule,
    MatNativeDateModule
} from '@angular/material';

还有什么我想念的吗?

推荐答案

您需要在导入下同时导入 MatDatepickerModule MatNativeDateModule 并添加 MatDatepickerModule 在提供者下

You need to import both MatDatepickerModule and MatNativeDateModule under imports and add MatDatepickerModule under providers

 imports: [
    MatDatepickerModule,
    MatNativeDateModule 
  ],
  providers: [  
    MatDatepickerModule,  
  ],

这篇关于角材料:MatDatepicker:找不到DateAdapter提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆