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

前端 未结 7 897
隐瞒了意图╮
隐瞒了意图╮ 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:58

    The documentation reiterates your findings here: https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service

    If my memory serves, $stateParams was introduced later than the original $state.params, and seems to be a simple helper injector to avoid continuously writing $state.params.

    I doubt there are any best practice guidelines, but context wins out for me. If you simply want access to the params received into the url, then use $stateParams. If you want to know something more complex about the state itself, use $state.

    0 讨论(0)
提交回复
热议问题