Answer the question
In order to leave comments, you need to log in
Where to store loadable data in Angular JS client?
On the main page of the web application, a list of, say, servers is loaded via the RESTful API, and each server has clusters, databases, all sorts of statistics, etc.
There is a breadcrumbs module, and when a user navigates from internal pages, let's say to the root of the site, where a list of servers is loaded, sometimes no servers appear. And it happens completely randomly.
I can't trace the pattern and cause yet. But I suspect that it would be necessary to store the already loaded data somewhere "normally".
I see an option to store in rootScope or localstorage, but it doesn't seem like a good practice to me.
Perhaps it's best not to store it anywhere, and load it every time?
I did not find any relevant articles on this topic, can you tell me something? :)
Answer the question
In order to leave comments, you need to log in
Well, as if you have a SPA - you make a service and store your data in it. Everything will live throughout the session. Those. 1 time downloaded and continue to use until the page is reloaded or something. You can ship when the first time is required.
I don’t know why I was stupid and didn’t look at the code before, it turns out that the problem is in the getClusters () function.
I display messages through the console (on the server and client) at each stage, and it turns out that sometimes !!! the request is just stupidly not sent =) The server simply does not receive the request =)
Interesting crap, I will deal with this phenomenon, just out of curiosity, if I don’t find it, I will store the data and not soar my brains =)
Do you have any ideas? Why can this function be stupid at times?
$scope.getClusters = function() {
console.log('getClusters() running');
$http.get('/home/clusters')
.then(function(response) {
console.log('Response was recieved.')
$scope.clusters= response.data;
$scope.displayedClusters= [].concat($scope.clusters);
/*console.log($scope);*/
})
.catch(function(error) {
console.error('home/clusters get request failed');
console.error(error);
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question