HTTP get content disappears after switching tabs


#1
factory('Menus', function ($q, $http) {
    api_url = 'http://api/menu';

    var respose_json = function () {
        var deferred = $q.defer();
        deferred.resolve(
            $http.get(api_url, {cache: true}).success(function (result) {
                return result;
            }));
        return deferred.promise;
    };

    return {
        all: respose_json,
        get: function (id) {
            return respose_json[id];
        }
    };

})

I’m trying to use cache to hold json data fetched from web so that after switching tabs, content will be ready without re-fetching. But, the content disappears every time switching tabs.
Is there anyway I can hold the data locally or in cache?


#2

Can you setup a CodePen sample with the actual code? In your get method in the factory, it looks like you’re trying to access a member in an array respose_json[id] . However, respose_json is a function.


#3

i kinda fixed the problem by using localstorage. but the content is one state late meaning it renders the previous get content.