UI-Router state.go call back on state change

前端 未结 2 550
终归单人心
终归单人心 2021-02-11 15:29

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 c

相关标签:
2条回答
  • 2021-02-11 15:43

    You may use state change listener.

     $rootScope
                .$on('$stateChangeSuccess',
                    function (event, toState, toParams, fromState, fromParams) {
                        //show alert()
                    });
    

    See State Change Events.

    0 讨论(0)
  • 2021-02-11 15:52

    $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.
    });
    
    0 讨论(0)
提交回复
热议问题