From d07172fb6e66cb7b69c3db93151e38c9f7d630bc Mon Sep 17 00:00:00 2001 From: Gonzalo Ruiz de Villa Date: Wed, 1 May 2013 01:19:44 +0200 Subject: [PATCH 1/2] fix(ngRepeat): correctly iterate over array-like objects Check if the object is array-like to iterate over it like it's done with arrays. Closes #2546 --- src/ng/directive/ngRepeat.js | 2 +- test/ng/directive/ngRepeatSpec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index a7d558957d2d..0fd53c2f6657 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -212,7 +212,7 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) { nextBlockOrder = []; - if (isArray(collection)) { + if (isArrayLike(collection)) { collectionKeys = collection; } else { // if object, extract keys, sort them and use to determine order of iteration over obj props diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 4372f57ab424..471bf4710380 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -55,6 +55,26 @@ describe('ngRepeat', function() { }); + it('should iterate over an array-like object', function() { + element = $compile( + '')(scope); + + document.body.innerHTML = "

" + + "a" + + "b" + + "c" + + "

"; + + var htmlCollection = document.getElementsByTagName('a'); + scope.items = htmlCollection; + scope.$digest(); + expect(element.find('li').length).toEqual(3); + expect(element.text()).toEqual('x;y;x;'); + }); + + it('should iterate over on object/map', function() { element = $compile( '