...">

Names of ui-sref parameters and state variables

I want to make a link, for example:

<a ui-sref="myState({myKey: 'my variable type value'})">

where the state name myState and the key myKey are variables.

Is there any way to do this?

+5
source share
6 answers

I ended up in the same situation, I couldn’t do this either, try moving your code using ng-click and inside your ng-click function use $ stage.go and pass the parameters there, for example:

 $scope.clickHandler = function(param){ $state.go('state.name',{myKey:param}); } 
+7
source

How to pass parameters using ui-sref to ui-router for controller

A similar question was asked here. His solution was to configure a state that performs routing, and you pass parameters to this state through ui-sref, which runs the desired URL

0
source

document ({id: document.id})

If your state is document /: id

0
source

I think the easiest solution is

 <button ui-sref="myState({mykey:vm.key})"> Link </button> 

where vm.key is the value passed from the controller. This avoids the use of additional javascript used in the response. Its very similar to the accepted answer, but the variable is used in the html tag as is, without creating a handler.

0
source

Dynamic ui-sref not supported, but I found advice on using link generation with the href $ state service method :

 <a href="{{ctrl.url(myState, myKey)}}> url = function(myState, myKey) { return $state.href(myState, {myKey: 'my variable type value'}); } 
0
source

Actually, I found a solution, so I hope it helps someone anyway.

 <li ng-repeat="item in array" ui-sref="stateName({param:{{item.key}}})"> Some content </li> 

In my case, I am using ui-router 1.0.15 , so I'm not sure if it will work with something older than v1.0.x

0
source

Source: https://habr.com/ru/post/1203806/


All Articles