Master/Detail Cache Navigation


#1

Hello there,
thank you for this project.

I have created a Master/Detail example in my end. I am collecting some RSS feeds into a page using the $http service and in this page I have implemented a client side pagination for these feeds. When I am going back through the ion-view after I have seen one feed of my collection (Detail page), it seems that the Master page and its $scope has been re-initialized. Therefore, I am losing the pagination in the Master page scope.

How can I manage this?

Best
George


#2

I solved this by using a localstorage service.


#3

Hello @TheJetlag,
I really appreciate your answer.

I am already using the local storage for saving my feeds and I am just reading the local storage only when I am receiving an error or timeout from the $http service in the Master Page. Could you please give me some more details about this service in your end? And how do you know when you click back, that your feeds have not been reloaded?

Thanks again

Best
George


#4

Hello,

In my scenario the master view always loads from localstorage (simple stringyfied json), only if the user forces a refresh (pul to refresh, or a button) I call a $http.

This means everytime I read and parse from localstorage when we get from detail back to the master. It really would be better to keep the $scope of the master view.


#5

Hello @TheJetlag,
I really appreciate your explanation. Now this is clear to me. But I think that this is an imporant issue or looks important only to me? What is your opinion?

Thanks for all
George


#6

This is standard behavior with AngularJS. When you navigate away from a view, it’s controller is destroyed. When you come back to that same view, the controller is reinitialized. So, your $scope will get reset.

The solution to this is not necessarily local storage. Local storage is for maintaining info between starts of the entire app. Say on a phone the user closes your app and reopens it days later. Local Storage is great for that.

Local Storage can also solve your problem, but it is not required.

For your problem, you need to be using a service. The service will stay in memory for as long as the app is still open. On your feed view, your controller should ask the service for the data to put on the scope. The service should do the $http call to get the data. If service should keep the response in memory in a variable. When the user navigates to an article, the service will not lose the previously fetched info.

Once the user returns to the list, the controller will have no data. So, it should request it from the service again. Because the service kept the previous results in a variable, it will return them to the controller.

So, your paging issue should be solved.

Do that help?


#7

You can put a cache option on your $http request { cache: true } and in your refresh remove the cache with $cacheFactory removeall.