How can I cache data returned from an ANgularJS $http call? -
I have some fingers JavaScript code that is called web service and creates an array array of objects:
< Pre> this. $ Http ({url: '/ api / action / getActions', method: "GET"}). Sevas ((data) => {self.ctions = data;})
< P> Is there any way I can cash it so that I do not need to access the server? I'm not sure that it makes a difference, but I use the protractor for my E2E tests. So I'm looking for a solution that will work with the controller. Ideally I would like to do this only with the AngularJS code and do not use an external library, unless really need it.
Here's a localStorage
.
var app = angular Module ('app', []); App.controller ('appCtrl', function ($ radius, $ http) {$ scope.getData = function () (if! LocalStorage.getItem ('ip')) {$ http.get ('http: // ip .jsontest.com / ') .success (function) {localStorage.setItem (' ip ', json.stringify (feedback)); $ scope.data = response $ scope.dataSource =' server ';})} Other {$ Scope.data = JSON.parse (localStorage.getItem ('IP')); $ scope.dataSource = 'cache';}};});
Comments
Post a Comment