What is required to use Angular 2 within IE9?

夙愿已清 提交于 2019-12-05 07:21:10

Fix for Angular2 RC4 IE9:

  • Include script:

<script src="https://npmcdn.com/angular2@2.0.0beta.17/es6/dev/src/testing/shims_for_IE.js"></script>

  • Change routing method to '#'

import { LocationStrategy, HashLocationStrategy } from '@angular/common'; ... bootstrap(AppComponent, [ ..., { provide: LocationStrategy, useClass: HashLocationStrategy } ]);

  • Don't use browser history to navigate:

window.history.back(); //BAD

So, after several hours of hair pulling, a conversation on here with @kevinB (thanks) and eventually raising a ticket https://github.com/angular/angular/issues/6479#issuecomment-171582759

it turns out it was human error!!

I had copy/pasted the wrong links from the cloudflare CDN site, referencing es6-sham.js instead of es6-shim.js

Such a small typo - but with massive consequences!

You can use the node package ie-shim, install on the command line using npm install ie-shim --save

Maybe reference in your ployfills.ts to import library on build:

import 'ie-shim';

Probably a good idea to include it before zone.js import.

Add this lines of code just after your <head> in index.html

Note: Order must be same

<script src="node_modules/es6-shim/es6-shim.min.js"></script> <script src="node_modules/systemjs/dist/system-polyfills.js"></script> <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>

happymeal

I'm using Angular 2.4.0 and was able to get it to work with IE9 with the following pollyfills:

<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/core-js/client/shim.min.js"></script>

I had expected the core-js shim to provide full support for IE9 too but it was still missing some functions. Adding shims_for_IE seemed to work well.

With regards to routing in IE9, the following answer was helpful: How to bootstrap with HashLocationStrategy in Angular 2 RC5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!