Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How do I extract query parameters using ui-router for AngularJS?

In AngularJS' own $location service I did

($location.search()).uid

to extract the parameter uid from a URL. What is the corresponding code for ui-router?

share|improve this question
 
Does this help stackoverflow.com/questions/11758079/… –  Gurpreet Singh Sep 27 at 15:04
 
Thanks, but no. That answer relates to Angular's built-in routing. I'm using ui-router (link above) for nested routing. –  Per Quested Aronsson Sep 27 at 15:24
add comment

2 Answers

up vote 1 down vote accepted

Unless you're binding to the query parameters (see the documentation), you don't access them directly through $state or $stateParams. Use the $location service.

share|improve this answer
 
Thanks for the clarification. I wasn't sure if that was the way to go. –  Per Quested Aronsson Sep 29 at 8:05
add comment

See the query parameters section of the URL routing documentation.

You can also specify parameters as query parameters, following a '?':

url: "/contacts?myParam" // will match to url of "/contacts?myParam=value"

For this example, if the url is /contacts?myParam=value then the value of $state.params will be: { myParam: 'value' }

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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