0

I am using ui-router. I have a state called user which displays a list of users and another state called user.edit which displays a form with a submit button. It is a nested state of user. If the user clicks submit the state will be transfered back to user like that: $state.transitionTo('user'); I would like the Controller of the user state to recognize that stateTransition and update some data.

I don't know where to start looking for a solution and would be glad for any hint.

Mr.H.
  • 965
  • 1
  • 10
  • 18
  • I think you need to use $onInit method, it will be called whenever your state is loaded. Also it is more convenient to use $state.go. See https://stackoverflow.com/questions/21105528/difference-between-state-transitionto-and-state-go-in-angular-ui-router for difference. – quantumThinker Jul 12 '17 at 07:15

1 Answers1

0

$routeChangeStart is what you are looking for !

Just take a look at the documention for $route, whenever a route change, this event will occur.

$rootScope.$on("$routeChangeStart", function (event, next, current) {
  //next is the next route information and current the current route.

 // you can check if its the right transition or not
});

You can also, while you are making the transition, trigger a custom event which will be listened by you user Controller.

Alburkerk
  • 1,564
  • 13
  • 19