I use AngularJS and ngView in my project.
ngView works perfectly with ngRoute, but when I come back to the previus link, ngView reload again data (with Ajax).
Is it possible to "keep in memory" previus data, so that should not always recharge all?
I use AngularJS and ngView in my project.
ngView works perfectly with ngRoute, but when I come back to the previus link, ngView reload again data (with Ajax).
Is it possible to "keep in memory" previus data, so that should not always recharge all?
You should store your data in localStorage (or cookieStorage if localStorage is not available), and manage your own cache policy. Then check in your controller if the data is Available and not expired before showing it up. I always use a service of my own that goes like:
(function () {
var __service = function () {
var __set = function (key, item) { localStorage.setItem(key, JSON.stringify(item)); };
var __get = function (key) { return (localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key)) : null); };
var __clear = function (key) { localStorage.removeItem(key); };
var __clearAll = function () { localStorage.clear(); };
return {
Set: __set,
Get: __get,
Clear: __clear,
ClearAll: __clearAll
};
};
angular.module('myApp').service('StorageService', __service);
}());
Then in my controllers I put that service to work in order to cache information that I do not want to retrieve everytime I get there.
PD: I know i must specialize that service to check if localStorage is available.