Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI-Router state.go call back on state change

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.

Controller:

$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); }); 
like image 320
fubbe Avatar asked Feb 28 '15 18:02

fubbe


1 Answers

$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. }); 
like image 156
Darth Egregious Avatar answered Sep 22 '22 16:09

Darth Egregious