Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 00d5fde

Browse files
kasobancaitp
authored andcommitted
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
1 parent 39f6e22 commit 00d5fde

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ng/cacheFactory.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
$scope.keys = [];
6868
$scope.cache = $cacheFactory('cacheId');
6969
$scope.put = function(key, value) {
70-
$scope.cache.put(key, value);
71-
$scope.keys.push(key);
70+
if ($scope.cache.get(key) === undefined) {
71+
$scope.keys.push(key);
72+
}
73+
$scope.cache.put(key, value === undefined ? null : value);
7274
};
7375
}]);
7476
</file>

0 commit comments

Comments
 (0)