`ui-router` $stateParams vs. $state.params

前端 未结 7 965
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 08:07

With ui-router, it\'s possible to inject either $state or $stateParams into a controller to get access to parameters in the URL. Howev

7条回答
  •  暖寄归人
    2020-12-07 08:52

    There are many differences between these two. But while working practically I have found that using $state.params better. When you use more and more parameters this might be confusing to maintain in $stateParams. where if we use multiple params which are not URL param $state is very useful

     .state('shopping-request', {
          url: '/shopping-request/{cartId}',
          data: {requireLogin: true},
          params : {role: null},
          views: {
            '': {templateUrl: 'views/templates/main.tpl.html', controller: "ShoppingRequestCtrl"},
            'body@shopping-request': {templateUrl: 'views/shops/shopping-request.html'},
            'footer@shopping-request': {templateUrl: 'views/templates/footer.tpl.html'},
            'header@shopping-request': {templateUrl: 'views/templates/header.tpl.html'}
          }
        })
    

提交回复
热议问题