Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 554
Per Quested Aronsson Avatar asked Sep 27 '13 15:09

Per Quested Aronsson


People also ask

How do I get query params from my Router?

import ActivatedRoute from '@angular/router'. Inject ActivatedRoute class in constructor. Access queryParams property of ActivatedRoute class which returns an observable of the query parameters that are available in the current URL route.

What is UI-Router in AngularJS?

Angular-UI-Router is an AngularJS module used to create routes for AngularJS applications. Routes are an important part of Single-Page-Applications (SPAs) as well as regular applications and Angular-UI-Router provides easy creation and usage of routes in AngularJS.

What is UI sref in AngularJS?

ui-sref stands for UI-Router state reference. It's a way to change states/state params (as defined in using the $stateProvider in a config block using the ui. router module for AngularJS. You can read the ui-sref documentation here.

What is $state in AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.


1 Answers

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' } 
like image 86
thisgeek Avatar answered Oct 14 '22 03:10

thisgeek