From 00d5fde49ca50eb777ac61541bdd9cc68fd52f20 Mon Sep 17 00:00:00 2001 From: Ole Weitz Date: Wed, 16 Jul 2014 13:05:54 +0200 Subject: [PATCH] docs($cacheFactory): prevent example breaking on key update The example for $cacheFactory breaks when a user tries to update a value for a key. Setting a new value for an existing key results in duplicate key entries in the key array, thus breaking the ng-repeat directive. With this fix the key is only added if it isn't contained in the cache. Closes #8214 --- src/ng/cacheFactory.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js index a6fcf233..c5914649 100644 --- a/src/ng/cacheFactory.js +++ b/src/ng/cacheFactory.js @@ -67,8 +67,10 @@ $scope.keys = []; $scope.cache = $cacheFactory('cacheId'); $scope.put = function(key, value) { - $scope.cache.put(key, value); - $scope.keys.push(key); + if ($scope.cache.get(key) === undefined) { + $scope.keys.push(key); + } + $scope.cache.put(key, value === undefined ? null : value); }; }]);