angular CacheFactory 没有设置任何值
angular CacheFactory doesn't set any value
我的 CacheFactory 模块有问题,问题是它没有设置任何东西!
这是我的代码,从逻辑上讲,当第一次代码是 运行 时,第二次刷新页面时它应该会显示值,但它不会,它始终是 '未定义'
function ItemFcy($http,$q,CacheFactory) {
var Items={};
var factory = {
getItems: Get
};
return factory;
function Get() {
var cache= CacheFactory.get('ItemsCache');
console.log("Cache value is:"+cache);
var deferred = $q.defer();
$http.get('/items.json')
.success(function(data, status, headers, config) {
Items= data;
CacheFactory.createCache('ItemsCache',Items);
deferred.resolve(Sliders);
return deferred.promise;
})
.error(function(data, status, headers, config) {
console.log("Error on loading items");
})
return deferred.promise;
}
它总是打印
Cache value is:undefined
为什么它没有设置任何东西?
我认为你应该使用 localStorage
而不是 cacheFoactory
ng-storage 可能对您有所帮助。
我的 CacheFactory 模块有问题,问题是它没有设置任何东西!
这是我的代码,从逻辑上讲,当第一次代码是 运行 时,第二次刷新页面时它应该会显示值,但它不会,它始终是 '未定义'
function ItemFcy($http,$q,CacheFactory) {
var Items={};
var factory = {
getItems: Get
};
return factory;
function Get() {
var cache= CacheFactory.get('ItemsCache');
console.log("Cache value is:"+cache);
var deferred = $q.defer();
$http.get('/items.json')
.success(function(data, status, headers, config) {
Items= data;
CacheFactory.createCache('ItemsCache',Items);
deferred.resolve(Sliders);
return deferred.promise;
})
.error(function(data, status, headers, config) {
console.log("Error on loading items");
})
return deferred.promise;
}
它总是打印
Cache value is:undefined
为什么它没有设置任何东西?
我认为你应该使用 localStorage
而不是 cacheFoactory
ng-storage 可能对您有所帮助。