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
use events
setup a listener in the list controller for example
$rootScope.$on("list:refresh" , function() { } );
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");
});
Sujan12
January 14, 2016, 12:37pm
3
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();
});
Sujan12
January 14, 2016, 12:47pm
5
Yes, but this is also executed when I go from the detail
screen back to the list
screen.
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