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

fix(ngRepeat): do not sort object keys alphabetically #10538

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
6 changes: 2 additions & 4 deletions src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,13 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
trackByIdFn = trackByIdExpFn || trackByIdArrayFn;
} else {
trackByIdFn = trackByIdExpFn || trackByIdObjFn;
// if object, extract keys, sort them and use to determine order of iteration over obj props
// if object, extract keys, in enumeration order, unsorted
collectionKeys = [];
for (var itemKey in collection) {
if (collection.hasOwnProperty(itemKey) && itemKey.charAt(0) != '$') {
if (collection.hasOwnProperty(itemKey) && itemKey.charAt(0) !== '$') {
collectionKeys.push(itemKey);
}
}
collectionKeys.sort();
}

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

39 changes: 20 additions & 19 deletions test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('ngRepeat', function() {
'</ul>')(scope);
scope.items = {age:20, wealth:20, prodname: "Bingo", dogname: "Bingo", codename: "20"};
scope.$digest();
expect(element.text()).toEqual('age:20|codename:20|dogname:Bingo|prodname:Bingo|wealth:20|');
expect(element.text()).toEqual('age:20|wealth:20|prodname:Bingo|dogname:Bingo|codename:20|');
});

describe('track by', function() {
Expand Down Expand Up @@ -587,7 +587,7 @@ describe('ngRepeat', function() {
'</ul>')(scope);
scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'};
scope.$digest();
expect(element.text()).toEqual('frodo:f:0|misko:m:1|shyam:s:2|');
expect(element.text()).toEqual('misko:m:0|shyam:s:1|frodo:f:2|');
});


Expand Down Expand Up @@ -656,10 +656,10 @@ describe('ngRepeat', function() {
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'};
scope.$digest();
expect(element.text()).
toEqual('doug:d:true-false-false|' +
'frodo:f:false-true-false|' +
'misko:m:false-true-false|' +
'shyam:s:false-false-true|');
toEqual('misko:m:true-false-false|' +
'shyam:s:false-true-false|' +
'doug:d:false-true-false|' +
'frodo:f:false-false-true|');

delete scope.items.doug;
delete scope.items.frodo;
Expand All @@ -681,15 +681,15 @@ describe('ngRepeat', function() {
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'};
scope.$digest();
expect(element.text()).
toBe('doug:d:true-false|' +
'frodo:f:false-true|' +
'misko:m:true-false|' +
'shyam:s:false-true|');
toBe('misko:m:true-false|' +
'shyam:s:false-true|' +
'doug:d:true-false|' +
'frodo:f:false-true|');

delete scope.items.frodo;
delete scope.items.shyam;
scope.$digest();
expect(element.text()).toBe('doug:d:true-false|misko:m:false-true|');
expect(element.text()).toBe('misko:m:true-false|doug:d:false-true|');
});


Expand All @@ -700,11 +700,12 @@ describe('ngRepeat', function() {
'</ul>')(scope);
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$toBeFilteredOut': 'xxxx'};
scope.$digest();

expect(element.text()).
toEqual('doug:d:true-false-false|' +
'frodo:f:false-true-false|' +
'misko:m:false-true-false|' +
'shyam:s:false-false-true|');
toEqual('misko:m:true-false-false|' +
'shyam:s:false-true-false|' +
'doug:d:false-true-false|' +
'frodo:f:false-false-true|');
});


Expand All @@ -716,10 +717,10 @@ describe('ngRepeat', function() {
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$toBeFilteredOut': 'xxxx'};
scope.$digest();
expect(element.text()).
toEqual('doug:d:true-false|' +
'frodo:f:false-true|' +
'misko:m:true-false|' +
'shyam:s:false-true|');
toEqual('misko:m:true-false|' +
'shyam:s:false-true|' +
'doug:d:true-false|' +
'frodo:f:false-true|');
});


Expand Down