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?
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.
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.
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.
$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.
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' }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With