Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 - How to Import Intl polyfill

I'm new to Ionic2 / Angular2 & I've been looking around and found several solutions for what needs to be done to fix the polyfill issue with using the intl date formatting (example answer here: Ionic 2, Using Angular 2 Pipe breaks on iOS—"Can't find variable: Intl" )

but what I do not understand and what no tutorial/stack overflow explanation has helped me to figure out, is where exactly and how exactly to accomplish this. I did npm install to get the intl package added to my node modules, but everything just says "then import it" but I don't know where to do that since I do not have a polyfill.ts file I could import it into, there's just the build/polyfill.js file & I tried importing directly into the .ts file which uses the intl date manipulation, but that did not resolve the issue.

It's possible that I don't comprehend something quite fundamental and that's why no one is explicitly stating where you'd need to import it, but can someone explain to me how to import this or refer me to a resource to explain what I am not understanding.

like image 962
Jake Boomgaarden Avatar asked Feb 20 '17 20:02

Jake Boomgaarden


1 Answers

Normally the polyfill.ts is imported in the app module file that'll bootstrap your application normally this is the main.ts file, so importing the needed polyfill in the app module bootstrap file should do the trick.

Here is an example:

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';
like image 183
Owain van Brakel Avatar answered Oct 12 '22 12:10

Owain van Brakel