Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 11 AngularJS error - Object doesn't support property or method 'from'

In my JavaScript I have a function detectEnvironmentAndGetLEAndDepot() which is called onload via HTML. I'm working with wicket, and need to take values held in the back-end, so I fire them to the screen, hide them, and search the <span> values from my JS for the name value, for example if(v.getAttribute('name') === 'LE'){do stuff} or if(v.getAttribute('name') === 'depot'){do stuff} (I'm sure not the most elegant solution, but I needed a quick one!). Then within the function detectEnvironmentAndGetLEAndDepot() I do a bit of formatting etc so the data is usable.

detectEnvironmentAndGetLEAndDepot() function (quite long, only relevant part) -

detectEnvironmentAndGetLEAndDepot = function() {

    Array.from(document.getElementsByTagName('span')).forEach(function(v) {

//Search name tag for particular names, then do formatting
}

When I open this in IE11 I get the error in a popup SCRIPT438: Object doesn't support property or method 'from' which is related to the first line of the method above - the Array class. Help much appreciated.

like image 456
notAChance Avatar asked Feb 23 '16 11:02

notAChance


2 Answers

As Array.from method is not supported by IE, you can try to use:

[].slice.call(document.getElementsByTagName('span')).forEach(function(v) {});

This doesn't require usage of any 3rd party libraries.

like image 141
Stanislav Kvitash Avatar answered Oct 10 '22 02:10

Stanislav Kvitash


You could use an ES2015 polyfill, like es6-shim, Array.from or Babel polyfill

like image 27
Tamas Hegedus Avatar answered Oct 10 '22 04:10

Tamas Hegedus