Following Material docs, I:
import {MdDatepickerModule} from '@angular/material';
in root module and added it in providers list, but coudln't use it in template. Got this error:
Uncaught (in promise): Error: MdDatepicker: No provider found for DateAdapter. You must import one of the following modules at your application root: MdNativeDateModule, or provide a custom implementation.
So according to it, I removed last import and added:
import {MdNativeDateModule} from '@angular/material';
And now, looks like, it works. Why Material docs tells to import MdDatepickerModule
, but not MdNativeDateModule
? And how they differ?
The example in the docs actually does import MdNativeDateModule
. Click on the plunker link and see the main.ts file. The docs are not as clear about this as would be preferred.
MdDatepickerModule
is the module containing the component itself. The component is agnostic to which implementation of dates you use with it.
For example, if you wished to use Moment.JS dates instead of JavaScript's native Date
objects, you could write your own class to work with Moment.JS objects. This is explained here.
If you simply want to work with JavaScript's Date
objects, though, you would need to use the NativeDateAdapter
class that is already included in @angular/material
. This class is provided by the MdNativeDateModule
.
It is not provided by MdDatepickerModule
since that module deals only with the UI component, and in case you were using Moment.JS objects, you would have no need for the NativeDateAdapter
class in your application.
you need to import MatNativeDateModule
from @angular/material
once you imported, you should have to import and export it in @NgModule
you can see on angular material
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With