Is it possible to call some function after transition? I mean after loading section. I tried with promise, but it called right after transition started.
$state.go('app.one.two').then(function(d){
// do staff
});
Thank you!
Is it possible to call some function after transition? I mean after loading section. I tried with promise, but it called right after transition started.
$state.go('app.one.two').then(function(d){
// do staff
});
Thank you!
Share Improve this question asked Jun 17, 2015 at 7:37 AlexAlex 511 silver badge5 bronze badges 1- you should thinnk of resolve option in state – Pankaj Parkar Commented Jun 17, 2015 at 7:41
4 Answers
Reset to default 5You need to look for stateChangeSuccess event. This event will be triggered on every stateChangeSuccess, hence, you have to place a check for your state in order to do some state specific work.
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
if(toState.name == 'app.one.two') {
//Do something
}
})
You could listen to the $state events
// Check if a state change happened
$scope.$on('$stateChangeSuccess',
function onStateSuccess(event, toState, toParams, fromState) {
//stuff
}
);
In the ui-router you can define onEnter
and onExit
callbacks maybe that might help you.
$state.go
return the promise so you have to pass some element after redirection state and then you can add callback function
$state.go('app.one.two', {null:null}).then(function(d){
// add functionality
});
Here I am passing null value with redirection state, if you have to pass any id or some data to next page then you can pass in {}
as a object