You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add documentation for MomentDateAdapter usage #7464
There should be at least a small guide (preferably official docs) about how to use the newly (in beta 11) introduced MomentDateAdapter for the datepicker.
What is the current behavior?
No docs at all.
What are the steps to reproduce?
Check release notes of beta 11 and be happy about these words:
I don't understand why then there is this extra information of adding the moment.js adapter to datepicker in release notes? I could have done this (custom adapter by extending) before beta 11, am I wrong with this assumption?
To use the adapter, you need to import MatMomentDateModule into your app module and you are good to go. You can use moment.Moment objects as ngModel for the date picker.
@mmalerba is there a way to change the output from iso fromat to some custom format. I dont want datepicker to work with time zones as the service crops the time part and hence when that time is given back to server we get wrong dates based on timezones
@Moutaz-homsi The best solution would be to use ControlValueAccessor and make a custom input component, this will have you in control of input and output of the component.
Full process for using Moment objects instead of Date objects.
npm i @angular/material-moment-adapter --save
npm i moment --save
Provide in your ngModule. import { MatMomentDateModule } from '@angular/material-moment-adapter';.
Your Datepickers will now automatically emit Moment objects
Reacted by Carlos Fonseca, Mike Graham, Rajkaran Chauhan, Jacek Piętal, JitinDhillon, TreesAndMountains, Gil Epshtain, Sunny Ngan, Adriano Bisca, Abhinav Upadhyay and 6 more
The DatePicker seems to be using Moment as dates just fine. But I have a model that has a Date as a property. I changed the type from Date to Moment but when my service retrieves data from the server the property of the model is just a string:
"2018-03-31T00:00:00"
Why is this not a Moment object? Am I missing something?
Activity
djleonskennedy commentedon Oct 2, 2017
@emreavsar You just need extend "DateAdapter" class
date-adapter.ts
and provide it
how to provide
For example; we don't use
moment.jscause it not good for 2017, we've usingdate-fnsand there was no problem to set adapter for itemreavsar commentedon Oct 2, 2017
I don't understand why then there is this extra information of adding the moment.js adapter to datepicker in release notes? I could have done this (custom adapter by extending) before beta 11, am I wrong with this assumption?
rkrzewski commentedon Oct 2, 2017
To use the adapter, you need to import
MatMomentDateModuleinto your app module and you are good to go. You can usemoment.Momentobjects asngModelfor the date picker.The problem that
@angular/material-moment-adaptermodule has not been published to https://npmjs.com yet. I worked around that by ripping out the sources from https://github.com/angular/material2/tree/master/src/material-moment-adapter/adapter and pasting them into a folder in my app's source tree. Works well enough for now, but I'd love to switch to a published version.Yeradon commentedon Oct 2, 2017
@rkrzewski You can use the builds repo: https://github.com/angular/material2-moment-adapter-builds. Just use
npm install https://github.com/angular/material2-moment-adapter-builds --saverkrzewski commentedon Oct 2, 2017
That worked like a charm @Yeradon, thanks!
yonatancohen commentedon Oct 8, 2017
Any example for using this?
kwalski commentedon Oct 10, 2017
+1 an example please
Yeradon commentedon Oct 17, 2017
@yonatancohen @kwalski https://stackblitz.com/edit/angular-material-moment-adapter-example
mmalerba commentedon Nov 8, 2017
The last 2 examples here are for moment adapter: https://material.angular.io/components/datepicker/examples
ankitraonka commentedon Nov 14, 2017
@mmalerba is there a way to change the output from iso fromat to some custom format. I dont want datepicker to work with time zones as the service crops the time part and hence when that time is given back to server we get wrong dates based on timezones
mohitvashishtha commentedon Nov 20, 2017
UPDATE: It is available on npm use following command to install it:
Moutaz-homsi commentedon Feb 9, 2018
@ankitraonka
i have the same issue , do you found any solution for this ?
ankitraonka commentedon Feb 10, 2018
@Moutaz-homsi The best solution would be to use ControlValueAccessor and make a custom input component, this will have you in control of input and output of the component.
Moutaz-homsi commentedon Feb 12, 2018
@ankitraonka, that's solve my problem for this issue , Have a great day and thanks a lot
kamok commentedon Feb 12, 2018
Full process for using
Momentobjects instead ofDateobjects.npm i @angular/material-moment-adapter --savenpm i moment --saveimport { MatMomentDateModule } from '@angular/material-moment-adapter';.Momentobjectsankitraonka commentedon Feb 13, 2018
@Moutaz-homsi
https://stackoverflow.com/questions/47262449/how-to-change-output-format-of-material-2-date-picker
Moutaz-homsi commentedon Feb 13, 2018
Thanks a lot @ankitraonka , this solved my issue , i repreduced the code here if anyone have the same problem : https://stackblitz.com/edit/angular-dlxnmx?file=app%2Fcva-date.component.ts
starquake commentedon Mar 23, 2018
The DatePicker seems to be using Moment as dates just fine. But I have a model that has a Date as a property. I changed the type from Date to Moment but when my service retrieves data from the server the property of the model is just a string:
"2018-03-31T00:00:00"
Why is this not a Moment object? Am I missing something?
angular-automatic-lock-bot commentedon Sep 10, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.