aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/directive/ngRepeat.js
diff options
context:
space:
mode:
authorMisko Hevery2013-04-11 16:28:42 -0700
committerMisko Hevery2013-04-11 23:06:07 -0700
commita0bc71e27107c58282e71415c4e8d89e916ae99c (patch)
tree774f767d2a780c32bed407e00637a97f1b9ac023 /src/ng/directive/ngRepeat.js
parenta491ea3791eb56e9932e12ded1395e0e5e99355a (diff)
downloadangular.js-a0bc71e27107c58282e71415c4e8d89e916ae99c.tar.bz2
fix(ngRepeat): prevent initial duplicates
Diffstat (limited to 'src/ng/directive/ngRepeat.js')
-rw-r--r--src/ng/directive/ngRepeat.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js
index 060f3392..a7d55895 100644
--- a/src/ng/directive/ngRepeat.js
+++ b/src/ng/directive/ngRepeat.js
@@ -153,7 +153,7 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
var animate = $animator($scope, $attr);
var expression = $attr.ngRepeat;
var match = expression.match(/^\s*(.+)\s+in\s+(.*?)\s*(\s+track\s+by\s+(.+)\s*)?$/),
- trackByExp, hashExpFn, trackByIdFn, lhs, rhs, valueIdentifier, keyIdentifier,
+ trackByExp, trackByExpGetter, trackByIdFn, lhs, rhs, valueIdentifier, keyIdentifier,
hashFnLocals = {$id: hashKey};
if (!match) {
@@ -166,13 +166,13 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
trackByExp = match[4];
if (trackByExp) {
- hashExpFn = $parse(trackByExp);
+ trackByExpGetter = $parse(trackByExp);
trackByIdFn = 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;
hashFnLocals.$index = index;
- return hashExpFn($scope, hashFnLocals);
+ return trackByExpGetter($scope, hashFnLocals);
};
} else {
trackByIdFn = function(key, value) {
@@ -233,7 +233,8 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
key = (collection === collectionKeys) ? index : collectionKeys[index];
value = collection[key];
trackById = trackByIdFn(key, value, index);
- if((block = lastBlockMap[trackById])) {
+ if(lastBlockMap.hasOwnProperty(trackById)) {
+ block = lastBlockMap[trackById]
delete lastBlockMap[trackById];
nextBlockMap[trackById] = block;
nextBlockOrder[index] = block;
@@ -243,10 +244,12 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) {
if (block && block.element) lastBlockMap[block.id] = block;
});
// This is a duplicate and we need to throw an error
- throw new Error('Duplicates in a repeater are not allowed. Repeater: ' + expression);
+ throw new Error('Duplicates in a repeater are not allowed. Repeater: ' + expression +
+ ' key: ' + trackById);
} else {
// new never before seen block
nextBlockOrder[index] = { id: trackById };
+ nextBlockMap[trackById] = false;
}
}