From dd58cc7ac152195b08c470865b4ba3854ad1916e Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Mon, 26 Oct 2015 11:58:49 +0100 Subject: [PATCH] fix(forEach): handle jQuery objects of length 0 Closes: #13169 --- src/Angular.js | 3 ++- test/AngularSpec.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index c1d1f8aeb487..ebf66d0680ec 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -193,7 +193,8 @@ msie = document.documentMode; function isNodeList(obj) { return typeof obj.length == 'number' && - typeof obj.item == 'function'; + (typeof obj.item == 'function' || + isString(obj.jquery)); } /** diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 35f30500156d..1f482c2903e3 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1142,6 +1142,11 @@ describe('angular', function() { forEach(jqObject, function(value, key) { log.push(key + ':' + value.innerHTML); }); expect(log).toEqual(['0:s1', '1:s2']); + + log = []; + jqObject = jqLite(""); + forEach(jqObject.children(), function(value, key) { log.push(key + ':' + value.innerHTML); }); + expect(log).toEqual([]); });