Skip to content

Commit 228b54a

Browse files
committed
ng:repeat ignores prototype keys
1 parent 00bb790 commit 228b54a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java $@

src/directives.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ angularWidget("@ng:repeat", function(expression, element){
162162
var children = [], currentScope = this;
163163
this.$onEval(function(){
164164
var index = 0, childCount = children.length, childScope, lastElement = reference,
165-
collection = this.$tryEval(rhs, reference);
165+
collection = this.$tryEval(rhs, reference), is_array = isArray(collection);
166166
for ( var key in collection) {
167+
if (is_array && !collection.hasOwnProperty(key)) break;
167168
if (index < childCount) {
168169
// reuse existing child
169170
childScope = children[index];

test/directivesSpec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,17 @@ describe("directives", function(){
9393
it('should ng:repeat over array', function(){
9494
var scope = compile('<ul><li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li></ul>');
9595

96-
scope.$set('items', ['misko', 'shyam']);
96+
Array.prototype.extraProperty = "should be ignored";
97+
scope.items = ['misko', 'shyam'];
9798
scope.$eval();
9899
expect(element.text()).toEqual('misko;shyam;');
100+
delete Array.prototype.extraProperty;
99101

100-
scope.$set('items', ['adam', 'kai', 'brad']);
102+
scope.items = ['adam', 'kai', 'brad'];
101103
scope.$eval();
102104
expect(element.text()).toEqual('adam;kai;brad;');
103105

104-
scope.$set('items', ['brad']);
106+
scope.items = ['brad'];
105107
scope.$eval();
106108
expect(element.text()).toEqual('brad;');
107109
});

0 commit comments

Comments
 (0)