Angular: 暂时更改区域设置无效
Angular: Changing locale in moment has no effect
我在我的应用程序中使用 angular2-moment 来处理日期。我有一个组件,在 moment 的帮助下像 datepicker 一样使用,现在我正在做本地化,我被本地化 moment 困住了。我写道:
console.log(moment().locale('de').format('LLLL'));
在我的构造函数中进行检查,但我仍然得到英文版本。我需要做任何特殊的导入工作吗?
添加后成功了:
import * as moment from 'moment';
import 'moment/min/locales';
我遇到了可能是同样的问题。由于我无法弄清楚的原因,来自 webpack 的语言环境文件是空的。
我发现的一个解决方法是将 moment
别名为 moment/min/moment-with-locales
。这并不理想,但它又可以使用语言环境了。
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',
},
},
我在我的应用程序中使用 angular2-moment 来处理日期。我有一个组件,在 moment 的帮助下像 datepicker 一样使用,现在我正在做本地化,我被本地化 moment 困住了。我写道:
console.log(moment().locale('de').format('LLLL'));
在我的构造函数中进行检查,但我仍然得到英文版本。我需要做任何特殊的导入工作吗?
添加后成功了:
import * as moment from 'moment';
import 'moment/min/locales';
我遇到了可能是同样的问题。由于我无法弄清楚的原因,来自 webpack 的语言环境文件是空的。
我发现的一个解决方法是将 moment
别名为 moment/min/moment-with-locales
。这并不理想,但它又可以使用语言环境了。
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',
},
},