我的服务中未定义$ stateParams对象的属性

时间:2017-03-06 22:21:23

标签: javascript angularjs

我正在尝试在服务中的$ stateParams对象上获取属性,当我console.log($stateParams)时,它显示属性'playerId'持有值但是当我console.log($stateParams.playerId)时,它显示未定义:

    app.factory('playerService', ['$http', '$state','$stateParams', 
        function ($http, $state, $stateParams) {

            var playerId = $stateParams.playerId;

            console.log($stateParams);  // logs - object{ playerId:"555"} 
            console.log($stateParams.playerId); // logs - undefined
        }

这是我的状态:

    $stateProvider
        .state('headless' , {
          abstract: true,
            url: "/:playerId",
            resolve: {
              liveData: function (playerService, $stateParams) {
                var live = playerService.getLive($stateParams.playerId); 
                return live;
              }
            },
            data: {
              headless: true
            }
       }.state('player.live', {
            url: "^/live/:playerId",
            templateUrl: "views/main_live_video_chat.html"
       })

任何想法发生了什么?

0 个答案:

没有答案