Angular 10 - 注册自定义语言环境

Tho*_*ras 7 typescript angular-i18n angular

由于 Angular 更新,我遇到了语言环境问题。

目前:

import localePl from '@angular/common/locales/pl';
registerLocaleData(localePl);
Run Code Online (Sandbox Code Playgroud)

它正在工作,但会导致错误:

app.module.ts 中的警告取决于@angular/common/locales/pl。CommonJS 或 AMD 依赖项可能会导致优化救助。

它在哪里工作?

  1. 我提供LOCALE_ID价值pl-PL
  2. DatePipe在 HTML 中使用。(变量 | 日期) -variable等于new Date()

测试方法:

1)

import localePl from '@angular/common/locales/global/pl'; registerLocaleData(localePl, 'pl-PL');

错误:

'无法读取管道的未定义属性'0'

在代码中: variable | date

其中变量等于 new Date()

2) 如果我完全删除registerLocaleData

错误:

缺少语言环境“pl-PL”的语言环境数据。对于管道“DatePipe”

Ben*_*ssa 12

我有同样的问题,要解决我在 app.module 中的问题:

添加

import '@angular/common/locales/global/pl
Run Code Online (Sandbox Code Playgroud)

消除

import localePl from '@angular/common/locales/pl';
Run Code Online (Sandbox Code Playgroud)

并删除“registerLocaleData”功能,保留LOCALE_ID提供程序设置。

我希望也对你有用。