user7966651
user7966651

Reputation: 51

onSuccess Transition Callback UI-router

I want to do some action when a particular state has been successfully transitioned. I have the following routing:

 angular.module('CurrencyModule')
    .config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
        $locationProvider.hashPrefix('');
        $stateProvider
            .state('currency', {
                url: '/currency',
                templateUrl: '/app/currency/page/list.html',
                controller: 'CurrencyListController as listCtrl',
            })
            .state('currency.create', {
                url: '/create',
                templateUrl: '/app/currency/page/create.html',
                controller: 'CurrencyCreateController as createCtrl',
            })
        ;
    })
;

and in CurrencyCreateController i have the following:

angular.module('CurrencyModule').controller('CurrencyCreateController', CurrencyCreateController);

CurrencyCreateController.$inject = ['$transitions']

function CurrencyCreateController($transitions) {
    var vm = this;

    $transitions.onSuccess({ to: 'currency.create', from: 'currency' }, function(transition) {
        console.log("Open the modal!");
    });
}

However, it never gets inside the callback? Why is that so!

Thanks!

Upvotes: 3

Views: 802

Answers (1)

johnny_swan
johnny_swan

Reputation: 21

The problem is that you need to register transition hook earlier, before CurrencyCreateController will init.

Upvotes: 2

Related Questions