mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-07 22:37:28 +08:00
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
This commit is contained in:
committed by
Caitlin Potter
parent
39f6e229c2
commit
00d5fde49c
@@ -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);
|
||||
};
|
||||
}]);
|
||||
</file>
|
||||
|
||||
Reference in New Issue
Block a user