Getting the next state from ionicView.beforeLeave

I know that angular has a function $stateChangeStart , which can perform actions as follows.

 $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { }); 

However, I am developing an ionic v1 application in which I would like to use a more intuitive way, which is the ionic life cycle. I am wondering if it is possible to get toState and toParams in $ionicView.beforeLeave since I cannot find the documentation on this. eg:

 $rootScope.$on('$ionicView.beforeLeave', function (event, toState, toParams) { }); 
+5
source share
2 answers

The ion event $ ionicView.beforeLeave can take a function with two arguments. From the argument you can only get from the state, it will not let you state.

  $rootScope.$on("$ionicView.beforeLeave", function(event, data){ // handle event console.log("Event: ", event); console.log("Data: ", data); }) 
+1
source

Therefore, I had to use a global state listener and hard code the views, as shown below:

  $rootScope.$on('$stateChangeStart', function(e, toState, toParams, fromState, fromParams) { var states_hidetab = [ 'app.shoppingcart', 'app.home-product', 'app.payment', 'app.shipping', 'app.review-order', 'app.points' ]; $rootScope.hideTabs = states_hidetab.includes(toState.name); }); 
0
source

Source: https://habr.com/ru/post/1263741/


All Articles