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

Commit

Permalink
fix(ngRepeat): add support to iterate an object's properties even if …
Browse files Browse the repository at this point in the history
…it does not inherit from Object

Closes #9964
  • Loading branch information
HeberLZ authored and petebacondarwin committed Sep 7, 2015
1 parent 912cbdd commit 7ea2c7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/directive/ngRepeat.js
Expand Up @@ -427,7 +427,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
// if object, extract keys, in enumeration order, unsorted
collectionKeys = [];
for (var itemKey in collection) {
if (collection.hasOwnProperty(itemKey) && itemKey.charAt(0) !== '$') {
if (hasOwnProperty.call(collection, itemKey) && itemKey.charAt(0) !== '$') {
collectionKeys.push(itemKey);
}
}
Expand Down
20 changes: 20 additions & 0 deletions test/ng/directive/ngRepeatSpec.js
Expand Up @@ -166,6 +166,26 @@ describe('ngRepeat', function() {
expect(element.text()).toEqual('age:20|wealth:20|prodname:Bingo|dogname:Bingo|codename:20|');
});


it('should iterate over on object created using `Object.create(null)`', function() {
element = $compile(
'<ul>' +
'<li ng-repeat="(key, value) in items">{{key}}:{{value}}|</li>' +
'</ul>')(scope);

var items = Object.create(null);
items.misko = 'swe';
items.shyam = 'set';

scope.items = items;
scope.$digest();
expect(element.text()).toEqual('misko:swe|shyam:set|');

delete items.shyam;
scope.$digest();
expect(element.text()).toEqual('misko:swe|');
});

describe('track by', function() {
it('should track using expression function', function() {
element = $compile(
Expand Down

0 comments on commit 7ea2c7f

Please sign in to comment.