6

I am working on ui-router. I have a state:

.state('new-personal-orders', {
    url: '/orders/new-personal-orders/:catId?',
    template: '<new-personal-orders></new-personal-orders>'
})  

In my controller i can make the state call with the

 $state.go('new-personal-orders',null,{reload:true})   

In the Html File i have an anchor tag:

<a href="/orders/new-personal-orders#12">Link</a>

If the tag is clicked the state changes and 'new-personal-orders' turns into the current state with the trailing hash in the url. The url then looks like:

http://localhost:3000/orders/new-personal-orders#12

I want to do the same from the controller file with the $state.go() function of ui-router. But the hash url is not added.

My question is that is there any way that the hash url can be passed by the $state.go() in ui-router?

2 Answers 2

9

It seems that you can now put a hash in the state params like so:

$state.go('new-personal-orders', {'#': catId });

And you don't even need a /:catId in the state configuration at all. See https://github.com/angular-ui/ui-router/pull/1867

0

You can pass state params as an argument in $state.go :

$state.go('new-personal-orders', {catId: 12}, {reload:true})  
// refers to: http://localhost:3000/orders/new-personal-orders/#12

It seems that you are attempting to implement the same inside an ng-repeat, then you should replace 12 by something such as order.catId etc.

2
  • Actually 12 is not a parameter that i want to pass . localhost:3000/orders/new-personal-orders#12. A Hash Url instead . Commented Dec 24, 2015 at 18:31
  • A hash url would automatically be constructed by using $state.go, if you define the stateParams correctly. It seems futile to manually re-construct the already referred url of a state. Commented Dec 24, 2015 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.