0

Is it possible to cache some http until parameters used in url change:

app.factory('dataService', function ($http,$rootScope) {
    return {
        getData: function () {
            return $http.get(rest.getData
           + $rootScope.number + "/" + $rootScope.blb
            ).then(function (result) {
                return result.data;
            });
        }
    }
});

So, when $rootScope.number changes in controller, I need to call http again, until then it should be cached. Is it possible and how?

2 Answers 2

1

Angular's $http has cache built in. Set cache as true in your $http request options:

$http.get(url, {cache: true}).then(...);
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to cache data you can do it in a number of ways.

You can cache it inside your service also.

  • Here is post which should help you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.