我在使用时遇到了一种我没有预料到的情况,$cacheFactory
存储在缓存中的对象不应该不受外部更改的影响$cacheFactory
,这意味着使用 $cacheFactory.get() 从缓存返回的对象不应将更改反映回当前缓存的对象。
我有一个演示:http: //jsfiddle.net/vladimir_ze/s9twdbup/
我在使用时遇到了一种我没有预料到的情况,$cacheFactory
存储在缓存中的对象不应该不受外部更改的影响$cacheFactory
,这意味着使用 $cacheFactory.get() 从缓存返回的对象不应将更改反映回当前缓存的对象。
我有一个演示:http: //jsfiddle.net/vladimir_ze/s9twdbup/
// get model from cache and modify it
$scope.modelFromCache = cache.get('model');
$scope.modelFromCache.author.name = 'Bob';
// Telling you're right and instead of copy you get a reference
console.log($scope.modelFromCache === cache.get('model')); // true
$scope.anotherModelFromCache = angular.copy(cache.get('model'));
// Solution if you just want a copy of cache property data
console.log($scope.anotherModelFromCache === cache.get('model')); // false
我认为你是对的,这种行为应该明确,因为
检索存储在 Cache 对象中的命名数据。
有点误导...
参考。https://docs.angularjs.org/api/ng/type/ $cacheFactory.Cache
顺便说一句,很好:)