Components: Datepicker dependencies docs

Created on 18 Feb 2020  路  2Comments  路  Source: angular/components

Documentation Feedback

When using MatMomentDateModule, it's not obvious how to get it working from the docs. Even googling gets you to slightly droll posts like https://github.com/angular/components/issues/12887

Affected documentation page:

If you go here:
https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings

It says to install moment.

If you go to Moment, it says to do:

npm i moment

You still get an error from import { MatMomentDateModule }

You must also do:

npm i @angular/material-moment-adapter

While Angular could probably say "that's Moment's issue" and Moment could say "No, that's Material's issue" I think it would be best to mention on the doc page here:

https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings

To say:

To install
npm i moment
npm i @angular/material-moment-adapter

In your module:
import { MatMomentDateModule, MomentDateAdapter } from "@angular/material-moment-adapter";

While https://github.com/angular/components/issues/12887 is certainly dead accurate, it shouldn't be necessary to google all over the place due to documentation terseness.

My guess: Most large development projects already have a package.json and an app.module.ts that's just loaded with all kinds of junk, so "it' just works". I was doing a coding challenge and going step by step and ran into this.

There are three other similar bugs, all of them locked, and none with a resolution.

(I do find in general, while the documentation is very beautiful, the "TS" tabs frequently don't show the proper module imports).

Seriously - big thumbs up to the look and feel of the docs, and the amazing completeness in most areas. Let's get it the rest of the way!

P3 materiadatepicker docs

Most helpful comment

I find this a very good point.

What is not so clear for me is that in one angular project I work, I use mat-datepicker with @angular/material-moment-adapter and I also in code do: import { Moment } from 'moment'; without having it installed through package.json how can this be?

Question for docs, do we really need to install moment?

All 2 comments

I find this a very good point.

What is not so clear for me is that in one angular project I work, I use mat-datepicker with @angular/material-moment-adapter and I also in code do: import { Moment } from 'moment'; without having it installed through package.json how can this be?

Question for docs, do we really need to install moment?

@x1c0 It might be that another dependency in your project brings in moment. The material-moment-adapter package just has a peer dependency on moment, so moment will never be brought in automatically by the @angular/material-moment-adapter package itself.

I agree though that the documentation about installing moment etc. could be more clear.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dzrust picture dzrust  路  3Comments

jelbourn picture jelbourn  路  3Comments

theunreal picture theunreal  路  3Comments

3mp3ri0r picture 3mp3ri0r  路  3Comments

RoxKilly picture RoxKilly  路  3Comments