Reputation: 969
I use angular2-moment for handling dates in my app. I have one component that is used like datepicker with help of moment, now I am doing localization and I am stuck with localizing moment. I wrote:
console.log(moment().locale('de').format('LLLL'));
in my constructor to check but I still get english version. Is there any special imports I need to do so this will work?
Upvotes: 1
Views: 6656
Reputation: 2825
I'm having what might be the same issue. For a reason I can't figure out, locale files from webpack are empty.
One workaround I've found is to alias moment
to moment/min/moment-with-locales
. It's not ideal but it gets working locales again.
resolve: {
modules: ['node_modules', ],
extensions: ['.js', '.jsx', '.react.js'],
mainFields: ['browser', 'jsnext:main', 'main'],
alias: {
// Ensure our moment is locale enabled.
moment: 'moment/min/moment-with-locales',
},
},
Upvotes: 1
Reputation: 969
It worked after I added:
import * as moment from 'moment';
import 'moment/min/locales';
Upvotes: 2