我是 Angular 初学者,我阅读了 Angular 的文档,对于这样一个基本的事情来说很难......我希望我的应用程序中的日期和其他内容具有法语区域设置,而不是默认的“en-US”。 ..
我开始阅读这篇 Angular文档 https://angular.io/guide/i18n,这似乎有点不完整,因为,我做了文档说明,但失败了:
>...\ClientApp>ng serve --configuration=fr
Configuration 'fr' could not be found in project 'ClientApp'.
好的,现在我看另一个文档页 https://angular.io/api/common/DatePipe在日期管上。它指出:
{{ value_expression | date [ : format [ : timezone [ : locale ] ] ] }}
但有关如何使用的任何示例locale
,所以,我尝试在测试应用程序中执行此操作link https://stackblitz.com/edit/angular-gitter-vjjuas, 像这样{{myDate | date: 'medium': undefined : 'fr'}}
但它什么也没显示...我在控制台中:
ERROR
Error: InvalidPipeArgument: 'Missing locale data for the locale "fr".' for pipe 'DatePipe'
我还应该做什么或安装什么才能在 Angular 中显示法语格式的日期?
Angular CLI: 6.1.5
Node: 8.11.1
OS: win32 x64
Angular: 6.1.8
尝试将以下代码添加到您的应用程序模块中
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
// the second parameter 'fr' is optional
registerLocaleData(localeFr, 'fr');
https://angular.io/guide/i18n#i18n-pipes https://angular.io/guide/i18n#i18n-pipes
编辑:
然后,如果您想将此区域设置设置为默认区域设置,则需要将 LOCALE_ID 注入令牌设置为“fr”,如下所示:
{provide: LOCALE_ID, useValue: 'fr' }
在您的应用程序模块中
希望能帮助到你
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)