Ionic 2,在iOS上使用Angular 2 Pipe break - “找不到变量:Intl” [英] Ionic 2, Using Angular 2 Pipe breaks on iOS—"Can't find variable: Intl"

查看:104
本文介绍了Ionic 2,在iOS上使用Angular 2 Pipe break - “找不到变量:Intl”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模板中使用日期,百分比和货币管道时遇到同样的问题 -

Experiencing the same problem with the date, percent, and currency pipes when using them in a template—

例如,我使用的是简单的百分比管道:

For example, I'm using a simple percent pipe:

{{ .0237| percent:'1.2-2' }}

在Chrome上运行时可行,但在部署到在iOS设备上,它会抛出此错误:

It works when running on Chrome, but when I deploy to an iOS device, it throws this error:


EXCEPTION:ReferenceError:找不到变量:[{{{{{。 0237 |百分比:'1.2-2'}} ...

"EXCEPTION: ReferenceError: Can't find variable: Intl in [{{ {{ .0237| percent:'1.2-2' }} ..."

还有其他人遇到过这个问题吗?任何建议或帮助将不胜感激!谢谢!

Has anyone else run into this problem? Any suggestions or help would be greatly appreciated! Thanks!

推荐答案

这是因为它依赖于内部化API,目前并非在所有浏览器中都可用(例如在iOS上不可用)浏览器)。

That's because it relies on the internalization API, which is not currently available in all browsers (for example not on iOS browser).

请参阅兼容性表

这是一个已知问题(beta.1 )。

This is a known issue (beta.1).

您可以尝试使用 polyfill for Intl

为此,您可以使用CDN版本,并将其添加到index.html:

To do so, you can use the CDN version, and add this to your index.html:

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>

或者如果您使用Webpack,您可以使用NPM安装Intl模块:

Or if you use Webpack, you can install the Intl module with NPM:

npm install --save intl

并将这些导入添加到您的应用中:

And add these imports to your app:

import 'intl';
import 'intl/locale-data/jsonp/en';

这篇关于Ionic 2,在iOS上使用Angular 2 Pipe break - “找不到变量:Intl”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆