Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(isArrayLike): Correct logic in isArrayLike to screen out objects #10186

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function isArrayLike(obj) {
return true;
}

return isString(obj) || isArray(obj) || length === 0 ||
return isString(obj) || isArray(obj) || (length === 0 && Object.keys(obj).length <= 1) ||
typeof length === 'number' && length > 0 && (length - 1) in obj;
}

Expand Down
2 changes: 0 additions & 2 deletions src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
}
collectionKeys.sort();
}

collectionLength = collectionKeys.length;
nextBlockOrder = new Array(collectionLength);

Expand Down Expand Up @@ -438,4 +437,3 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
}
};
}];

10 changes: 10 additions & 0 deletions test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<ul>' +
'<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$index}}|</li>' +
'</ul>')(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() {
Expand Down