fub*_*bbe 33 angularjs angular-ui-router
成功调用state.go时我需要回调,并设置我的警报消息.在调用state.go之后,当前消息被推送到数组.State.go调用控制器,包含警报消息的数组设置为空.
结果,不会显示警告消息.
控制器:
$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);
});
Run Code Online (Sandbox Code Playgroud)
Dar*_*ous 94
$state.go() 返回一个承诺.
所以做以下事情:
$state.go('wherever', {whenever: 'whatever'}).then(function() {
// Get in a spaceship and fly to Jupiter, or whatever your callback does.
});
Run Code Online (Sandbox Code Playgroud)
您可以使用状态更改侦听器.
$rootScope
.$on('$stateChangeSuccess',
function (event, toState, toParams, fromState, fromParams) {
//show alert()
});
Run Code Online (Sandbox Code Playgroud)
请参阅状态更改事件.
| 归档时间: |
|
| 查看次数: |
28831 次 |
| 最近记录: |