diff --git a/src/Angular.js b/src/Angular.js index aab712d3e1ee..e533d6f74000 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -201,7 +201,7 @@ function isArrayLike(obj) { return true; } - return isString(obj) || isArray(obj) || length === 0 || + return isString(obj) || isArray(obj) || ((length === 0) && !isObject(obj)) || typeof length === 'number' && length > 0 && (length - 1) in obj; } diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 69192cc4a3fb..af99d881f6e1 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -344,7 +344,6 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { } collectionKeys.sort(); } - collectionLength = collectionKeys.length; nextBlockOrder = new Array(collectionLength); @@ -438,4 +437,3 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { } }; }]; - diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 00e36be69a7f..589719cbd2bb 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -580,6 +580,16 @@ describe('ngRepeat', function() { expect(element.text()).toEqual('frodo:f:0|misko:m:1|shyam:s:2|'); }); + it('should expose iterator offset as $index when iterating over objects with length key value 0', function() { + element = $compile( + '')(scope); + scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f', 'length':0}; + scope.$digest(); + expect(element.text()).toEqual('frodo:f:0|length:0:1|misko:m:2|shyam:s:3|'); + }); + it('should expose iterator position as $first, $middle and $last when iterating over arrays', function() {