diff options
| author | Pete Bacon Darwin | 2013-01-11 12:47:38 +0000 | 
|---|---|---|
| committer | Igor Minar | 2013-01-17 00:25:30 -0800 | 
| commit | 7e746015ea7dec3e9eb81bc4678fa9b6a83bc47c (patch) | |
| tree | 39a7c731f3e92552a05828e4598524cd036610c4 /src/ng/directive/ngRepeat.js | |
| parent | 8c269883fd4353414ea5b6cf77c80bfa54a4ae2f (diff) | |
| download | angular.js-7e746015ea7dec3e9eb81bc4678fa9b6a83bc47c.tar.bz2 | |
fix(ngRepeat): correctly apply $last if repeating over object
If the $last property is calculated from the original collectionLength
on an object and properties starting with $ were filtered out, then $last
is never applied and $middle is applied erroniously.
Closes #1789
Diffstat (limited to 'src/ng/directive/ngRepeat.js')
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 15 | 
1 files changed, 10 insertions, 5 deletions
diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 893ad442..c59fefac 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -92,14 +92,17 @@ var ngRepeatDirective = ngDirective({        scope.$watch(function ngRepeatWatch(scope){          var index, length,              collection = scope.$eval(rhs), -            collectionLength = size(collection, true), -            childScope, +            cursor = iterStartElement,     // current position of the node              // Same as lastOrder but it has the current state. It will become the              // lastOrder on the next iteration.              nextOrder = new HashQueueMap(), +            arrayLength, +            childScope,              key, value, // key/value of iteration -            array, last,       // last object information {scope, element, index} -            cursor = iterStartElement;     // current position of the node +            array, +            last;       // last object information {scope, element, index} + +          if (!isArray(collection)) {            // if object, extract keys, sort them and use to determine order of iteration over obj props @@ -114,6 +117,8 @@ var ngRepeatDirective = ngDirective({            array = collection || [];          } +        arrayLength = array.length; +          // we are not using forEach for perf reasons (trying to avoid #call)          for (index = 0, length = array.length; index < length; index++) {            key = (collection === array) ? index : array[index]; @@ -149,7 +154,7 @@ var ngRepeatDirective = ngDirective({            childScope.$index = index;            childScope.$first = (index === 0); -          childScope.$last = (index === (collectionLength - 1)); +          childScope.$last = (index === (arrayLength - 1));            childScope.$middle = !(childScope.$first || childScope.$last);            if (!last) {  | 
