【发布时间】:2020-02-16 00:45:19
【问题描述】:
标题是我需要的。我的应用程序中有一个语言选择器下拉菜单,到目前为止,我一直在使用它来动态(不刷新页面)更改应用程序中的语言。当我尝试使用 moment.js'moment.locale(string) 执行此操作时,它不会像应用程序的其余部分那样更新视图。
setLocale(locale?: string) {
if (!locale) locale = localStorage.getItem("locale") || "en-US";
localStorage.setItem("locale", locale);
this.adapter.setLocale(locale); //for date picker (nothing to do with moment.js)
moment.locale(locale); // for moment.js ------------------- only works after refresh
this.translate.use(locale); //rest of the app
}
这是从下拉列表中选择一种语言时调用的方法,但 moment.js 呈现的日期不会更新,而是直到页面刷新。
有没有办法做到这一点?黑客?解决方法?
谢谢
【问题讨论】:
-
试试this。