diff options
| author | jankuca | 2013-09-24 13:51:28 -0700 |
|---|---|---|
| committer | Igor Minar | 2013-09-25 09:42:01 -0700 |
| commit | 31c56f540045b5270f5b8e235873da855caf3486 (patch) | |
| tree | 6a1fd7c9849122dabe71154c28bde4f7b9a91fc0 /src/ng/directive/ngRepeat.js | |
| parent | f8f8f754b02459bb789247476cc0da63d2d7370f (diff) | |
| download | angular.js-31c56f540045b5270f5b8e235873da855caf3486.tar.bz2 | |
fix(ngRepeat): correctly track elements even when the collection is initially undefined
Previously if the collection model was set to undefined on the first digest,
the repeater would get confused and not use the correct tracking function
for associating model with dom elements in the repeater.
Closes #4145
Closes #3964
Diffstat (limited to 'src/ng/directive/ngRepeat.js')
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 50be2a61..16a810ef 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -218,7 +218,8 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { return function($scope, $element, $attr){ var expression = $attr.ngRepeat; var match = expression.match(/^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/), - trackByExp, trackByExpGetter, trackByIdFn, trackByIdArrayFn, trackByIdObjFn, lhs, rhs, valueIdentifier, keyIdentifier, + trackByExp, trackByExpGetter, trackByIdExpFn, trackByIdArrayFn, trackByIdObjFn, + lhs, rhs, valueIdentifier, keyIdentifier, hashFnLocals = {$id: hashKey}; if (!match) { @@ -232,7 +233,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { if (trackByExp) { trackByExpGetter = $parse(trackByExp); - trackByIdFn = function(key, value, index) { + trackByIdExpFn = function(key, value, index) { // assign key, value, and $index to the locals so that they can be used in hash functions if (keyIdentifier) hashFnLocals[keyIdentifier] = key; hashFnLocals[valueIdentifier] = value; @@ -275,6 +276,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { childScope, key, value, // key/value of iteration trackById, + trackByIdFn, collectionKeys, block, // last object information {scope, element, id} nextBlockOrder = []; @@ -282,9 +284,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { if (isArrayLike(collection)) { collectionKeys = collection; - trackByIdFn = trackByIdFn || trackByIdArrayFn; + trackByIdFn = trackByIdExpFn || trackByIdArrayFn; } else { - trackByIdFn = trackByIdFn || trackByIdObjFn; + trackByIdFn = trackByIdExpFn || trackByIdObjFn; // if object, extract keys, sort them and use to determine order of iteration over obj props collectionKeys = []; for (key in collection) { |
