Michael W. Czechowski
Michael W. Czechowski

Reputation: 3455

Trigger event after $state.go()

Is it possible to trigger an event after the state was changed in ui.router? Strictly speaking I am working with ionic framework with angularJS and considering it uses angular-ui-router.

Attention: Pseudo code I'd like to use.

$state.go('app.list').then(function(){ DO SOMTHING });

It is not state specific. Should be usable for any given state.

Upvotes: 2

Views: 1743

Answers (1)

Shadow Wizzard
Shadow Wizzard

Reputation: 66396

You can't do it directly, as far as I know, however as you can see in the answer to this question, you can watch for state change and add your code in there:

$rootScope.$on('$stateChangeSuccess', 
    function(event, toState, toParams, fromState, fromParams){ 
        if (toState == 'app.list') {
            //DO SOMTHING
        }
    }
);

Upvotes: 4

Related Questions