Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular ui.router dynamic ui-sref

I have an app with 2 states:

  • profile
  • settings

I have a link that repeats in my whole app:

<a ui-sref="profile({id:profile.id})" ui-sref-active="active">Current state + ID</a>

How can I change the ui-sref to be dynamic? - to represent the current state along with the current stateParam that I want (which is id)

when finding a solution, keep in mind that I want to be abble to use ui-sref-active so I'd rather avoid ng-click on something like this.

like image 775
user3800799 Avatar asked Feb 07 '23 15:02

user3800799


1 Answers

I think ui-sref will parse what is inside the ( and ) as an expression.

So all you have to do is this.

<a ng-repeat="step in steps" ui-sref="{{step.state}}(step.param)"></a>
like image 119
Muhammad Usman Avatar answered Feb 13 '23 06:02

Muhammad Usman