角度:如何以法语格式显示日期 [英] Angular: How to display a date in French format
问题描述
我是Angular的初学者,我阅读了Angular的文档,很难做到这一点……我希望我的应用程序中的日期和其他内容具有法语语言环境,而不是默认的'en-美国 ...
我开始阅读此Angular 文档,似乎有点不完整,原因是我做了文档说明,但失败了:
> ... \ClientApp> ng serve --configuration = fr
在项目'ClientApp'中找不到配置'fr'。
好的,现在我看另一个文档页面。它指出:
{{value_expression |日期[:格式[:时区[:区域设置]]}}}
但是有任何示例使用语言环境
,因此,我尝试在测试应用程序中进行操作链接,例如 {{myDate | date:'medium':undefined:'fr'}}
但它什么也不显示...我在控制台中有:
错误
错误:InvalidPipeArgument:'管道'DatePipe'
我还应该怎么做或安装才能在Angular中显示法语格式的日期?
Angular CLI:6.1.5
节点:8.11.1
操作系统:win32 x64
Angular:6.1.8
尝试将以下代码添加到应用模块
从'@ angular / common'导入{registerLocaleData};来自 @ angular / common / locales / fr的
导入localeFr;
//第二个参数'fr'是可选的
registerLocaleData(localeFr,'fr');
https://angular.io/guide/i18n#i18n-pipes
编辑:
然后,如果需要要将此语言环境设置为默认语言,则需要将LOCALE_ID注入令牌设置为 fr,例如:
{提供:LOCALE_ID, useValue:'fr'}
在您的应用模块中
希望有帮助
I am an Angular beginner, I read the documentation of Angular, and it's hard for such an elementary thing... I want that the dates and other things in my application have the French locale, and not the default 'en-US'...
I started to read this Angular documentation, that seems a little bit incomplete, cause, I did the doc states, and failed:
>...\ClientApp>ng serve --configuration=fr
Configuration 'fr' could not be found in project 'ClientApp'.
OK, now I look on another documentation page on the Date pipe. It states:
{{ value_expression | date [ : format [ : timezone [ : locale ] ] ] }}
but ANY example on how to use the locale
, so, I tried to do it in a test application link, like this {{myDate | date: 'medium': undefined : 'fr'}}
but it displays nothing... I have in the console:
ERROR
Error: InvalidPipeArgument: 'Missing locale data for the locale "fr".' for pipe 'DatePipe'
what else should I do or install to display in Angular a date in the French format?
Angular CLI: 6.1.5
Node: 8.11.1
OS: win32 x64
Angular: 6.1.8
Try adding to your app module the following code
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
EDIT: Then if you want to sets this locale as default you need to set the LOCALE_ID injection token as 'fr' like that :
{provide: LOCALE_ID, useValue: 'fr' }
In your app module
Hope it helps
这篇关于角度:如何以法语格式显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!