Angular 4 / Angular-cli:具有国际化的日期 Polyfill API 不起作用
Angular 4 / Angular-cli: Date Polyfill with Internationalization API does not work
我似乎无法让国际化的 polyfill API 工作。
如文档中所述 (https://angular.io/docs/ts/latest/guide/pipes.html)
只需向您的 index.html 添加一个脚本:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.de"></script>
所有错误显示日期管道的问题都应该消失。但是这个问题仍然存在。
在另一个网页 (https://coryrylan.com/blog/adding-the-internationalization-polyfill-to-a-angular-cli-project) 上,我发现了一个更受欢迎的解决方案,即安装国际化 API 并将其添加到 angular src 文件夹中的 polyfills.ts
。
应该 npm run install intl --save
然后像
import 'intl';
import 'intl/locale-data/jsonp/de.js';
一样导入 intl polyfill 但这也不起作用。
有没有人成功地将日期 polyfill 添加到 Angular 4?
有人建议使用来自 moment.js
的自定义管道,但这对我来说不是一个解决方案 (),因为像 angular 这样强大的野兽应该提供这样的功能.也许我做错了什么?
您不能随意使用 angulars datePipe 来格式化日期。像这样:| date: 'HH:mm'
这在 chrome 中有效,但不能在边缘显示:08:15
。您可以为此使用 Angular 的 'shortTime' 管道。
编辑 2017 年 5 月 8 日:
在 Safari 中仍然面临 InternationalizationAPI 问题的任何人:
确保你传递了一个像 {{"2016-07-03T12:33Z" | date 'dd.MM.yyyy'}}
这样的日期,所以你需要它的 ISO 字符串表示才能工作(只在 safari 中需要),谢谢苹果。
我似乎无法让国际化的 polyfill API 工作。 如文档中所述 (https://angular.io/docs/ts/latest/guide/pipes.html) 只需向您的 index.html 添加一个脚本:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.de"></script>
所有错误显示日期管道的问题都应该消失。但是这个问题仍然存在。
在另一个网页 (https://coryrylan.com/blog/adding-the-internationalization-polyfill-to-a-angular-cli-project) 上,我发现了一个更受欢迎的解决方案,即安装国际化 API 并将其添加到 angular src 文件夹中的 polyfills.ts
。
应该 npm run install intl --save
然后像
import 'intl';
import 'intl/locale-data/jsonp/de.js';
一样导入 intl polyfill 但这也不起作用。
有没有人成功地将日期 polyfill 添加到 Angular 4?
有人建议使用来自 moment.js
的自定义管道,但这对我来说不是一个解决方案 (
您不能随意使用 angulars datePipe 来格式化日期。像这样:| date: 'HH:mm'
这在 chrome 中有效,但不能在边缘显示:08:15
。您可以为此使用 Angular 的 'shortTime' 管道。
编辑 2017 年 5 月 8 日:
在 Safari 中仍然面临 InternationalizationAPI 问题的任何人:
确保你传递了一个像 {{"2016-07-03T12:33Z" | date 'dd.MM.yyyy'}}
这样的日期,所以你需要它的 ISO 字符串表示才能工作(只在 safari 中需要),谢谢苹果。