As an angular user, I too shudder at the title of this question, due to the fact that IE8 is evil incarnate and should be put down like a rabid dog.
that being said, I was wondering if anyone else has run into the issue of loading Angular 1.3 in IE8, and the page breaking before load and just reporting an error: Object Expected
on an if condition that uses the isArray() function. (isArray() is also found in Angular 1.2, so it confuses me that it works there but not in 1.3)
So that everyone understands my reasons for this, my company recently took the step of no longer supporting IE8 on new development. But our new UI needs to support IE8 on the initial landing page ONLY, so that users can still access our old software that supports IE8. I was hoping that I could use 1.3, and just write small tweaks for the landing page until it is also out from underneath IE8.
Overarching question: is it possible to use Angular 1.3 with IE8 at all, or will I be forced to use 1.2 until we completely remove IE8 support?
From Angular Developer Guide migration docs:
I tried L0lander's answer (which was my preferred one), but when using older angular version, other scripts complained, and it ended up not working anyway. So, I checked statistics at my site, and 0,2% only use IE8 or less, and I won't be giving myself headache over such a small crowd, so I simply added a message asking users of IE8 or less to upgrade.
Add following code just after
body
tag to all of your pages:Github user @fergaldoyle maintains a repo that combines shiming/polyfill and other patch strategies in order to maintain compatibility.
This could be a viable strategy for many solution providers
Based on answers from SamHuckaby and Zenorbi, i came up with acceptable solution which is a combination of their ideas and insights from this article IF Internet Explorer THEN Do Something Else (A How To...) by Phil Nash:
<!--[if !IE]>-->...<!--<![endif]-->
- Conditional comment will be evaluated byIE
, but the scripts within won't get loaded byIE
and will get loaded by all other browsers<!--[if gt IE 8]>...<![endif]-->
- Conditional comment will be evaluated byIE
and if greater than IE 8, scripts will get loaded<!--[if lt IE 9]>...<![endif]-->
- Conditional comment will be evaluated byIE
and if less than IE 9, scripts will get loaded.Both
es5-shim
andes6-shim
should be put out ofIE8
conditional comment block and checked by all browsers (and it's not expensive operation) as i recently found out thatSafari
has issues withString.prototype.startsWith()
Yeah we have some code duplication inside the first and the second conditional comment (and it can't be solved in a different way) but we have zero unwanted scripts loaded and we can close our task here.
There is a way, though it's a bit rough. Below is the code you need to load before angular and your app may run. This is a collection of shims/polyfills, mostly from Mozilla Developer Network some by me.
Please note, that this only allows AngularJS to run, it doesn't update the JS runtime of IE8. So things like
somePromise.catch(...)
won't work, you must writesomePromise["catch"](...)
.If you have angular-bootstrap, you also need to "patch" the angular.min.js file, because angular-boostrap uses
{in: someCondition}
, but because of the older JS runtime thein
keyword is reserved and will fail in the code generation.Find:
var e=(b?"s":'((l&&l.hasOwnProperty("'+a+'"))?l:s)')+"."+a;
Replace:
var e=(b?"s":'((l&&l.hasOwnProperty("'+a+'"))?l:s)')+"['"+a+"']";
Per the comments on the question, and Zenorbi's answer, Angular 1.3 does NOT load correctly in IE8 anymore. It was never designed to continue working in IE8, so this should not come as a surprise.
I actually came up with a simple workaround that will make page load times slightly slower for any IE8 users which is an acceptable loss for me.
using this code, I can simply load 1.3 by default, and if any IE8 users load the page, it will simply load angular 1.2 directly afterwards, simply overwriting any duplicated code:
note: This is terrible practice generally. If we were making a larger effort to support IE8 users, I would go with Zenorbi's answer, since it allows you to load only one version of angular.