Execute code when view is entered from "below" or "beside" on the view stack but not from "above"

I have this app that has 4 views:

login   ->   list   ->  detail
        ->   misc

Now I’m looking for some code that reloads the view list when it is entered from login or misc, but not when I navigated to detail and use the back button to get back to list. Any idea how I could solve this?

I thought about using $ionicView events, but couldn’t find out how to differentiate between where the user comes from:

$scope.$on('$ionicView.beforeEnter', function() {
  reload();
});

This (or with $ionicView.enter) reloads every time the view is shown :confused:

use events

  1. setup a listener in the list controller for example

$rootScope.$on("list:refresh" , function() { } );

  1. broadcast the event … You can do this in 2 steps, first $state.go to the list view, then broadcast … for example

             $state.go('list').then(function(){
         $rootScope.$broadcast("list.refresh");
             });

Good idea! This could work, thanks.

Can I somehow only execute the refresh functionality when the actually enters the screen that will display the refreshed information?

you already doing that?

$scope.$on('$ionicView.beforeEnter', function() {
  reload();
});

Yes, but this is also executed when I go from the detail screen back to the listscreen.

Well … you could try

$rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState)

it holds the from and next state …

1 Like

Personally I would not do this … just do manually refresh