Go back and keep previous screen intact

Hi, I have a problem and I need help. I have a screen with a list loaded by $http.get and JSON. When I click on an item, it goes to another screen with the item details. Now, when I go back it loads the list again with $http.get, how can I do that without reload the screen and keep the list screen intact?

I tried with:

var goBack = function() {
    $ionicNavBarDelegate.back();
  }

and also with

var goBack = function() {
   $state.go('list');
  }

Thank you!

It’s unlikely you’re going to be able to do that (well it’s out of my scope of knowledge at least).

How I’ve handled that in the past and seen it handled is to use a modal to display the detail info (you can force a modal to fullscreen thereby looking like you changed state when you didn’t) that way when you go back, the scope isn’t re-loaded and everything is as you left it.

If no one has an answer for you, you could consider a slight change to your application architecture to achieve that :smile:

Thank you, @edwrede_ZA. It’s a good point of view, but the details screen has tabs and it’s more complicated to do that option. Let’s see if someone has a better solution, but I think it’s something essential in a mobile application.

Only a pleasure :smile:

I think the problem you’re going to run into is that every time you change state, your scope is going to re-load… Well that’s how I understand it at least!

Alternatively what you could do is use a cache for the HTTP data, when you go back from your detail view, check if the data is in the cache, then do not fire the HTTP request again. You’ll need to implement some kind of pull to refresh or auto refresh then as well though!

Well @mserrano008 , in fact you can, and I’ve used this before on angular but not in ionic.

What you’re looking for is the sticky state and/or the deep-state-redirect of ui-router-extra http://christopherthielen.github.io/ui-router-extras/#/sticky

If you have any questions regarding any of these, feel free to ask :slight_smile:

Best

2 Likes

Great info @WidawskiJ thank you :slight_smile:

Also, in beta 14 (and the nightlies) there is view caching, which may solve your issue. If you put your http call in the controller it will only be called the first time the view is loaded and therefore the list won’t be reloaded until that view is no longer cached.

From Please help test: Angular 1.3, improved transitions, cached views (repost):

I’m not sure if this will solve your problem but I wanted to throw it out there!

1 Like

Thank you @brandyshea. I will check it! :wink:

1 Like

Finally I solved the problem. First I downloaded the beta 13 nigthly version: http://code.ionicframework.com/#nightly

After that, I tried with:

 var goBack = function() {
   $state.go('list');
  }

and it works for me! :slight_smile:

1 Like