From c8c6b47084b6e387e526afd7dd1476a8f2b69d28 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 array already. --- src/ng/cacheFactory.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ng/cacheFactory.js b/src/ng/cacheFactory.js index a6fcf23351da..3a82daf5a212 100644 --- a/src/ng/cacheFactory.js +++ b/src/ng/cacheFactory.js @@ -68,7 +68,9 @@ $scope.cache = $cacheFactory('cacheId'); $scope.put = function(key, value) { $scope.cache.put(key, value); - $scope.keys.push(key); + if($scope.keys.indexOf(key) === -1) { + $scope.keys.push(key); + } }; }]);