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

Fix ngRepeat to allow keys starting with $ #8845

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
// if object, extract keys, sort them and use to determine order of iteration over obj props
collectionKeys = [];
for (var itemKey in collection) {
if (collection.hasOwnProperty(itemKey) && itemKey.charAt(0) != '$') {
if (collection.hasOwnProperty(itemKey) && !(itemKey.charAt(0) === '$' && itemKey.charAt(1) === '$')) {
collectionKeys.push(itemKey);
}
}
Expand Down
14 changes: 12 additions & 2 deletions test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ describe('ngRepeat', function() {
expect(element.text()).toEqual('misko:swe|shyam:set|');
});

it('should iterate over an object/map and not strip keys that begin with $', function() {
element = $compile(
'<ul>' +
'<li ng-repeat="(key, value) in items">{{key}}:{{value}}|</li>' +
'</ul>')(scope);
scope.items = {'$1 - $10':'low price', '$11 - $20':'high price'};
scope.$digest();
expect(element.text()).toEqual('$1 - $10:low price|$11 - $20:high price|');
});

it('should iterate over an object/map with identical values', function() {
element = $compile(
'<ul>' +
Expand Down Expand Up @@ -688,7 +698,7 @@ describe('ngRepeat', function() {
'<ul>' +
'<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$first}}-{{$middle}}-{{$last}}|</li>' +
'</ul>')(scope);
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$toBeFilteredOut': 'xxxx'};
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$$toBeFilteredOut': 'xxxx'};
scope.$digest();
expect(element.text()).
toEqual('doug:d:true-false-false|' +
Expand All @@ -703,7 +713,7 @@ describe('ngRepeat', function() {
'<ul>' +
'<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$even}}-{{$odd}}|</li>' +
'</ul>')(scope);
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$toBeFilteredOut': 'xxxx'};
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f', '$$toBeFilteredOut': 'xxxx'};
scope.$digest();
expect(element.text()).
toEqual('doug:d:true-false|' +
Expand Down