Reputation: 51
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
Reputation: 21
The problem is that you need to register transition hook earlier, before CurrencyCreateController will init.
Upvotes: 2