I am trying to figure out why my angular 2 app is stuck on showing Loading... when running in IE 11.
Following someone's suggestion, I've tried this plunker, posted by someone on stack overflow, on both chrome and IE 11. Works fine on Chrome, but fails on IE 11. Same error, stuck on saying "Loading..."
The plunker is : https://plnkr.co/edit/6zVFbrH5yohwc714gBbk?p=preview
<!DOCTYPE html>
<html>
<head>
<script>document.write('<base href="' + document.location + '" />');</script>
<title>Router Sample</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.34.2/es6-shim.min.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/angular2.dev.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.1/http.dev.js"></script>
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'src': {defaultExtension: 'ts'}}
});
System.import('src/boot')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<my-app>loading...</my-app>
</body>
</html>
Anybody got any idea as to why IE 11 fails to run the angular 2 app?
Thank you!
The latest version of
angular
is only setup for evergreen browsers by default...See here for more information on browser support along with a list of suggested polyfills for specific browsers. https://angular.io/guide/browser-support#polyfill-libs
This means that you manually have to enable the correct polyfills to get Angular working in IE11 and below.
To achieve this, go into
polyfills.ts
(in thesrc
folder by default) and just uncomment the following imports:Note that the comment is literally in the file, so this is easy to find.
If you are still having issues, you can downgrade the
target
property toes5
intsconfig.json
as@MikeDub
suggested. What this does is change the compilation output of anyes6
definitions toes5
definitions. For example, fat arrow functions (()=>{}
) will be compiled to anonymous functions (function(){}
). You can find a list of es6 supported browsers here.Notes
• I was asked in the comments by
@jackOfAll
whether IE11 polyfills are loaded even if the user is in an evergreen browser which doesn't need them. The answer is, yes they are! The inclusion of the IE11 polyfills will take your polyfill file from~162KB
to~258KB
as of Aug 8 '17. I have invested in trying to solve this however it does not seem possible at this time.• If you are getting errors in IE10 and below, go into you
package.json
and downgradewebpack-dev-server
to2.7.1
specifically. Versions higher than this no longer support "older" IE versions.What worked for me is I followed the following steps to improve my application perfomance in IE 11 1.) In Index.html file, add the following CDN's
2.) In polyfills.ts file and add the following import:
EDIT 2018/05/15: This can be achieved with a meta tag; please add that tag to your index.html and disregard this post.
This is not a complete answer to the question (for the technical answer please refer to @Zze's answer above), but there's an important step that needs to be added:
COMPATIBILITY MODE
Even with the appropriate polyfills in place, there are still issues with running Angular 2+ apps using the polyfills on IE11. If you are running the site off an intranet host (ie. if you are testing it at http://localhost or another mapped local domain name), you must go into Compatibility View settings and uncheck "Display intranet sites in Compatibility View", since IE11's Compatibility View breaks a couple of the conventions included in the ES5 polyfills for Angular.
If you have still problems that not all JavaScript functions are working add this line in your polyfills. It fixes the missing ‘values’ method:
And this line fixes the missing ‘includes’ method: