Masoud Motallebipour
Masoud Motallebipour

Reputation: 414

angular CacheFactory doesn't set any value

I'm having issue with CacheFactory module and the problem is that It does not set anything!

here is my code, logically when the first time the code is run, the second time when I refresh the page it should show me the value but it doesn't and it's always 'undefined'

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;
  }

it always print

Cache value is:undefined

why it doesn't set anything?

Upvotes: 0

Views: 149

Answers (1)

atinder
atinder

Reputation: 2090

I think you should be using localStorage rather than cacheFoactory

ng-storage might be helpful for you.

Upvotes: 1

Related Questions