How to extract query parameters with ui-router for AngularJS?

Per Quested Aronsson picture Per Quested Aronsson · Sep 27, 2013 · Viewed 92.1k times · Source

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?

Answer

thisgeek picture thisgeek · Nov 23, 2013

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' }