From 228b54aa2ea9c5faf9280f39317fdf07b2d49580 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 9 Jul 2010 14:45:29 -0700 Subject: ng:repeat ignores prototype keys --- java | 2 ++ src/directives.js | 3 ++- test/directivesSpec.js | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100755 java diff --git a/java b/java new file mode 100755 index 00000000..da0e133b --- /dev/null +++ b/java @@ -0,0 +1,2 @@ +#!/bin/sh +/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java $@ diff --git a/src/directives.js b/src/directives.js index 1b422331..a333c4c4 100644 --- a/src/directives.js +++ b/src/directives.js @@ -162,8 +162,9 @@ angularWidget("@ng:repeat", function(expression, element){ var children = [], currentScope = this; this.$onEval(function(){ var index = 0, childCount = children.length, childScope, lastElement = reference, - collection = this.$tryEval(rhs, reference); + collection = this.$tryEval(rhs, reference), is_array = isArray(collection); for ( var key in collection) { + if (is_array && !collection.hasOwnProperty(key)) break; if (index < childCount) { // reuse existing child childScope = children[index]; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 836c51e8..df0b5b94 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -93,15 +93,17 @@ describe("directives", function(){ it('should ng:repeat over array', function(){ var scope = compile(''); - scope.$set('items', ['misko', 'shyam']); + Array.prototype.extraProperty = "should be ignored"; + scope.items = ['misko', 'shyam']; scope.$eval(); expect(element.text()).toEqual('misko;shyam;'); + delete Array.prototype.extraProperty; - scope.$set('items', ['adam', 'kai', 'brad']); + scope.items = ['adam', 'kai', 'brad']; scope.$eval(); expect(element.text()).toEqual('adam;kai;brad;'); - scope.$set('items', ['brad']); + scope.items = ['brad']; scope.$eval(); expect(element.text()).toEqual('brad;'); }); -- cgit v1.2.3