admin 管理员组文章数量: 1086019
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
本文标签: javascriptCall some function after statego will finishStack Overflow
版权声明:本文标题:javascript - Call some function after $state.go will finish - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743988650a2514316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论