0

我遇到了 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;
  }

它总是打印

缓存值为:未定义

为什么它没有设置任何东西?

4

1 回答 1

1

我认为你应该使用localStorage而不是cacheFoactory

ng-storage可能对你有帮助。

于 2015-08-31T08:00:36.930 回答