简体   繁体   English

Angular UI路由器-通过路由传递动态数据?

[英]Angular UI router - Pass dynamic data with a route?

I have a couple of routes/states defined in my application. 我在应用程序中定义了几个路由/状态。 Consider the standard use case of list view and single view. 考虑列表视图和单一视图的标准用例。 For my single view, I pass the id as a URL parameter. 对于我的单一视图,我将id作为URL参数传递。 I want to pass some more data, but not as URL parameters. 我想传递更多数据,但不传递URL参数。 Can this be done? 能做到吗? I use $state.go for transitioning to states. 我使用$state.go过渡到州。

Edit: 编辑:

$stateProvider
    .state('list', {
        url: '/list',
        ...
    })
    .state('single', {
        url: '/single/:id',
        ...
    });

I get the id in the $stateParams in the respective controller, from the URL. 我从URL获取相应控制器的$stateParams中的id But I want to send more dynamic data to this route, without sending it through the URL. 但我想向该路由发送更多动态数据,而不通过URL发送。 How would I do it? 我该怎么办?

You can pass the additional params like this. 您可以像这样传递其他参数。

  state('state_name', {
        url: 'state_url',
        template: '<template></template>',
        params : params
    })

You can get the values by using the $state.current 您可以使用$ state.current获取值。

$state.current.param

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM