我正在使用ngx-bootstrap进行工作,我需要datepicker的locale部分。https://valor-software.com/ngx-bootstrap/#/datepicker#locales我在上面的网站上查看了一下,我看到了这个:
On this picture i can see "en" locale which shows an english datepicker starting on sunday
问题:我的app.module.ts中只有"enGb“区域设置可用
Here "en" locale causes an error
有什么解决方案可以让我在周日启动"enGb“日期选择器,也可以在周日自动启动"en”语言环境。
提前感谢您的关注。
(我使用@2.0.5 ngx-bootstrap版本)
发布于 2018-07-11 16:16:41
我对这个问题的解决方案是改变:
defineLocale('en', enLocale); // throws error because enLocale doesn't exist至:
defineLocale('en'); // works, week is starting on sunday根据它们的源文件,'en‘是不使用配置参数时使用的默认语言。我还没有找到任何关于这个问题的文档,所以我希望这将对其他面临这个问题的人有用。
发布于 2020-01-07 19:56:01
在我的angular项目升级期间,我为ngx-bootstrap (版本:2.0.5)调整了以下内容:
// OLD CODE: import { defineLocale } from 'ngx-bootstrap/bs-moment';
import { defineLocale } from 'ngx-bootstrap/chronos';
// OLD CODE: import { nl, es, enGb } from 'ngx-bootstrap/locale';
import { nlLocale, esLocale, enGbLocale} from 'ngx-bootstrap/locale';
setLocale(lang: string) {
// Default locale corresponds with lang
let locale = lang;
switch (lang) {
case 'nl': {
// OLD CODE: defineLocale('nl', nl);
defineLocale('nl', nlLocale);
break;
}
...
}然后它就成功了。
发布于 2018-06-04 23:18:02
编辑:找到可能的解决方案,从它们的源文件中,看起来您必须导入区域设置,而不是从locale文件夹,而是从ngx-bootstrap/chronos文件夹
这是我试图远离ngx-bootstrap的众多原因之一,他们有很多bug,还有很多他们从未解决过的问题。他们遇到了下拉列表不能正常工作的问题,就像在6个月的大部分时间里,他们不确定他们是否曾经修复过这个问题。我使用https://ng-bootstrap.github.io/#/home作为替代。
另外,在他们的github:https://github.com/valor-software/ngx-bootstrap/blob/development/src/locale.ts上检查这个文件,你会注意到enLocale也不在那里。因此,这看起来是valorsoft的另一个bug。
我没有使用过他们的名为chronos的库,但是如果您在项目中安装了chronos库,您可以尝试直接从chronos库中导入。(快速google搜索不会返回任何关于chronos库的信息。)
https://stackoverflow.com/questions/50683534
复制相似问题