UI-Router state.go回调状态更改 [英] UI-Router state.go call back on state change

查看:150
本文介绍了UI-Router state.go回调状态更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成功调用state.go后,我需要一个回调,并设置我的警报消息. 当前,在调用state.go之后,消息被推送到数组. State.go调用控制器,并将包含警报消息的数组设置为空.

I need a callback when state.go has been invoked successfully, and set my alert message. Currently the message is pushed to the array, after state.go has been called. State.go calls the controller, and the array containing the alert message is set to empty.

结果,将不会显示任何警报消息.

Result, no alert message will be shown.

控制器:

$scope.alerts = []; // empty array, initialized on startup
.....
// This could be any function
.success(function(data, status, headers, config, statusText){
     $state.go($state.current, {}, {reload : true});
     $scope.alerts.push({type : 'success', msg : status});
})
.error(function(error){
    console.log(error.message);
});

推荐答案

$state.go()返回承诺.

请执行以下操作:

$state.go('wherever', {whenever: 'whatever'}).then(function() {
  // Get in a spaceship and fly to Jupiter, or whatever your callback does.
});

这篇关于UI-Router state.go回调状态更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆