具有嵌套路由的Ui-Router $ stateParams

时间:2015-12-14 03:45:45

标签: angularjs angular-ui-router

我试图在嵌套状态下使用所选对象的id值路由到网址,但它无效。

ROUTER:
 .state('sessions.editor', {
    url: '/editor/:id',
    templateUrl: 'views/editor.html',
    controller: 'EditorCtrl'
  })

CONTROLLER (EditorCtrl): 
  $scope.theSession.$id = $stateParams.id;
  //$scope.session object is successfully returned with the $id property. 


PREVIOUS CONTROLLER:

//when button is clicked
$state.go('sessions.editor');

但是,当我尝试将其设置为$ stateParams时,id属性变为未定义。我用$ scope.session上的另一个属性测试了这个,当我尝试将它设置为$ stateParams时,该属性也变得未定义。

我认为麻烦与嵌套状态有关。这是对的吗?

1 个答案:

答案 0 :(得分:0)

我认为您需要将params键添加到UI-Router的状态,例如:

    .state('sessions.editor', {
        url: '/editor/:id',
        controller: 'EditorCtrl',
        templateUrl: 'views/editor.html',
        params: {
            id: {
                value : '',//Default
                squash: false
            }
        }
    })

然后在EditorCtrl中使用您现有的实现$stateParams

相关问题