diff --git a/src/Angular.js b/src/Angular.js index 88ea452b3749..386682a325e7 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -213,7 +213,9 @@ function forEach(obj, iterator, context) { if (obj) { if (isFunction(obj)){ for (key in obj) { - if (key != 'prototype' && key != 'length' && key != 'name' && obj.hasOwnProperty(key)) { + // Need to check if hasOwnProperty exists, + // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function + if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) { iterator.call(context, obj[key], key); } } diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 36d4926e709b..7fe65f4c8051 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -504,6 +504,21 @@ describe('angular', function() { expect(log).toEqual(['0:a', '1:c']); }); + if (document.querySelectorAll) { + it('should handle the result of querySelectorAll in IE8 as it has no hasOwnProperty function', function() { + document.body.innerHTML = "
"; + + var htmlCollection = document.querySelectorAll('[name="x"]'), + log = []; + + forEach(htmlCollection, function(value, key) { log.push(key + ':' + value.innerHTML)}); + expect(log).toEqual(['0:a', '1:c']); + }); + } it('should handle arguments objects like arrays', function() { var args,