$ stateParams参数undefined

时间:2017-06-22 12:23:00

标签: angularjs angular-ui-router

我有以下路由:

$stateProvider
    .state('message', {
        parent: 'admin',
        url: '/message',
        templateUrl: './app/gol88/admin/messaging/page/list.page.html',
        controller: 'ListController as listCtrl'
    })
    .state('replyMessage', {
        parent: 'message',
        url: '/{ticketId:int}/reply', //this should have {id} as stateParams
        onEnter: ['$mdDialog', '$state', function($mdDialog, $state) {
            $mdDialog.show({
                controller: ReplyController,
                controllerAs: 'replyCtrl',
                templateUrl: '/app/gol88/admin/messaging/page/dialog/reply.html',
                parent: angular.element(document.body),
                clickOutsideToClose:true
            }).then(function(response) {

            }, function() {
                $state.go('message');
            });
        }],
        onExit: ['$mdDialog', function($mdDialog) {
            $mdDialog.hide();
        }]
    })
;

当我第一次尝试导航到replyMessage状态并在我的Controller中使用$ stateParams.ticketId时,我得到了值。但是,当我转换到消息状态,并尝试再次转换回replyMessage状态时,$ stateParams.ticketId现在未定义。为什么会这样?

这是我对replyMessage状态的控制器:

    var ReplyForm = require('../model/reply_form.model');

ReplyController.$inject = ['$stateParams', 'TicketApiService'];

function ReplyController($stateParams, TicketApiService) {
    var vm = this;

    vm.ticket = null;
    vm.ReplyForm = ReplyForm;

    vm.addComment = addComment;

    init();

    function init() {
        console.log($stateParams.ticketId);
       /* TicketApiService.details($stateParams.ticketId)
            .then(function(response) {
                vm.ticket = response;
            })
        ;*/
    }

    function addComment() {
        TicketApiService.addComment($stateParams.ticketId, vm.ReplyForm.toPayload())
            .then(function(response) {s.
                vm.ticket.comments.unshift(response);
                vm.ReplyForm.reset();
            })
        ;
    }
}

module.exports = ReplyController;

0 个答案:

没有答案