Dynamically constructed ui-sref attribute in ui-router

前端 未结 2 1082
萌比男神i
萌比男神i 2020-12-09 04:52

I am new to angular and especially ui-router.

Here is a link:

SomeText

The link

相关标签:
2条回答
  • 2020-12-09 05:05

    Try to use a simple name for state as 'topics' and use 'topics/:topicId' as url property. After that you can use ui-sref='topics({topicId: topic.id})'

    0 讨论(0)
  • 2020-12-09 05:25

    You are almost there. Just the parameter must be part of the URL definition, not the name of the state:

    .state('topics',{
        url: '/{id:[0-9]{1,8}}', // we can also add some constraint, like int id only
        templateUrl: "",
        controller: ""
     })
    

    And how to call it (where currentItem.id would be injected dynamically as a part of some ng-repeat)

    <a ui-sref="topics({id:currentItem.id})">SomeText</a>
    

    Because ui-sref means: ui-sref='stateName({param: value, param: value}). More info here:

    • ui router, URL Parameters
    • ui-sref
    0 讨论(0)
提交回复
热议问题