CurrencyCreateController

CurrencyCreateController

当特定状态成功转换后,我想执行一些操作。我有以下路由:

 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',
            })
        ;
    })
;

在CurrencyCreateController中,我具有以下内容:
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!");
    });
}

但是,它永远不会进入回调内部吗?为什么!

谢谢!

最佳答案

问题在于,您需要在CurrencyCreateController初始化之前先注册过渡挂钩。

09-25 19:19