gpt4 book ai didi

angular - Ionic 2 - 如何导入 Intl polyfill

转载 作者:太空狗 更新时间:2023-10-29 17:23:14 26 4
gpt4 key购买 nike

我是 Ionic2/Angular2 的新手,我一直在四处寻找并找到了几个解决方案来解决使用国际日期格式的 polyfill 问题(此处的示例答案:Ionic 2, Using Angular 2 Pipe breaks on iOS—"Can't find variable: Intl")

但我不明白的是,没有教程/堆栈溢出解释帮助我弄清楚,究竟在哪里以及如何完成这个。我执行了 npm install 以将 intl 包添加到我的节点模块中,但所有内容都只是说“然后导入它”,但我不知道在哪里做,因为我没有可以将其导入的 polyfill.ts 文件,只有 build/polyfill.js 文件,我尝试直接导入到使用国际日期操作的 .ts 文件,但这并没有解决问题。

可能我不理解一些非常基本的东西,这就是为什么没有人明确说明您需要导入它的位置,但是有人可以向我解释如何导入它或向我推荐资源来解释什么我不明白。

最佳答案

通常 polyfill.ts 导入到 app 模块 文件中,这通常会引导您的应用程序这是 main.ts 文件,因此在 app 模块 Bootstrap 文件应该可以解决问题。

这是一个例子:

ma​​in.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';

关于angular - Ionic 2 - 如何导入 Intl polyfill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42353543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com