Ionic 2 - 如何导入 Intl polyfill
Ionic 2 - How to Import Intl polyfill
我是 Ionic2 / Angular2 的新手,我一直在四处寻找并找到了几个解决方案来解决使用 intl 日期格式的 polyfill 问题(此处的示例答案:Ionic 2, Using Angular 2 Pipe breaks on iOS—"Can't find variable: Intl" )
但我不明白的是,没有 tutorial/stack 溢出解释帮助我弄清楚,究竟在哪里以及如何完成这个。我执行了 npm install 以将 intl 包添加到我的节点模块,但一切都只是说 "then import it" 但我不知道在哪里做,因为我没有 polyfill.ts 文件我可以导入它进入,只有 build/polyfill.js 文件,我尝试直接导入到使用国际日期操作的 .ts 文件,但这并没有解决问题。
可能我不理解一些非常基本的东西,这就是为什么没有人明确说明您需要导入它的位置,但是有人可以向我解释如何导入它或向我推荐资源解释一下我不明白的地方。
通常 polyfill.ts 导入到 app 模块 文件中,该文件将 bootstrap 您的应用程序通常是 main.ts 文件,所以在 app 模块 bootstrap 文件中导入所需的 polyfill 应该可以解决问题。
这是一个例子:
main.ts
import './polyfills.ts';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {enableProdMode} from '@angular/core';
import {environment} from './environments/environment';
import {AppModule} from './app/app.module';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
polyfill.ts
// All needed polyfills for example web animations
import 'web-animations-js/web-animations.min';
我是 Ionic2 / Angular2 的新手,我一直在四处寻找并找到了几个解决方案来解决使用 intl 日期格式的 polyfill 问题(此处的示例答案:Ionic 2, Using Angular 2 Pipe breaks on iOS—"Can't find variable: Intl" )
但我不明白的是,没有 tutorial/stack 溢出解释帮助我弄清楚,究竟在哪里以及如何完成这个。我执行了 npm install 以将 intl 包添加到我的节点模块,但一切都只是说 "then import it" 但我不知道在哪里做,因为我没有 polyfill.ts 文件我可以导入它进入,只有 build/polyfill.js 文件,我尝试直接导入到使用国际日期操作的 .ts 文件,但这并没有解决问题。
可能我不理解一些非常基本的东西,这就是为什么没有人明确说明您需要导入它的位置,但是有人可以向我解释如何导入它或向我推荐资源解释一下我不明白的地方。
通常 polyfill.ts 导入到 app 模块 文件中,该文件将 bootstrap 您的应用程序通常是 main.ts 文件,所以在 app 模块 bootstrap 文件中导入所需的 polyfill 应该可以解决问题。
这是一个例子:
main.ts
import './polyfills.ts';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {enableProdMode} from '@angular/core';
import {environment} from './environments/environment';
import {AppModule} from './app/app.module';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
polyfill.ts
// All needed polyfills for example web animations
import 'web-animations-js/web-animations.min';