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

查看:19
本文介绍了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() 返回一个promise.

$state.go() returns a promise.

所以做一些类似的事情:

So do something like:

$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天全站免登陆