我需要将params和查询传递给ui-sref

时间:2016-04-19 13:54:32

标签: angularjs angular-ui-router

我需要使用带有参数和查询参数的ui-sref在角度应用上动态构建到另一条路线的链接。例如:

    <a class="clr-secondary" ui-sref="app.topic.individual.conversation.single
({cid:comment.activityItemId, cid:itemId})">{{comment.subject}}</a>

这构造了一个类似于

的链接
www.website.com/pass/11/conversations/178

我还需要在此末尾添加一个查询参数,以便整个网址看起来像

www.website.com/pass/11/conversations/178?comment_id=126

1 个答案:

答案 0 :(得分:3)

将查询参数添加到ui路由器配置中的URL:

.state('yourstate', {
  url: '/pass/:activityId/conversations/:conversationId?comment_id',
  templateUrl: 'path/to/template',
  controller: 'YourController'
});

然后传递comment_id,就像传递其他参数一样:

<a class="clr-secondary" ui-sref="app.topic.individual.conversation.single
({activityId:comment.activityItemId, conversationId:itemId, comment_id: 126})">{{comment.subject}}</a>