Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
143
rated 0 times [  147] [ 4]  / answers: 1 / hits: 135188  / 6 Years ago, sun, april 8, 2018, 12:00:00

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:




Error: MatDatepicker: No provider found for DateAdapter.




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';


Is there anything else I'm missing?


More From » angular

 Answers
32

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



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

[#54724] Thursday, April 5, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tylerdamiena

Total Points: 139
Total Questions: 90
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
tylerdamiena questions
;