Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular material: MatDatepicker: No provider found for DateAdapter

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?

like image 583
ajgisme Avatar asked Apr 08 '18 17:04

ajgisme


People also ask

How can use Datepicker in angular materials?

mat-datepicker example Add a template reference variable mat-datepicker element. Connect mat-datepicker to input element via [matDatepicker] property. Finally add date picker toggle button to display or hide calender popup by using mat-datepicker-toggle element.

How do I disable mat Datepicker?

To control the disabled state of the mat-datepicker-toggle, in a consistent, repeatable manner, by setting the same property on the input element.


1 Answers

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

 imports: [     MatDatepickerModule,     MatNativeDateModule    ],   providers: [       MatDatepickerModule,     ], 
like image 103
Sajeetharan Avatar answered Sep 22 '22 10:09

Sajeetharan