AngularJS — Read URL Parameters


AngularJS provides you with an easy to use service which allows you to access url and route parameters.

This service is called $routeParams.

To use this service you have to add is as dependency to your controller. All the parameters are stored using an associative array, so they are easy to access.

Here you find a complete example:

app.controller('TestCtrl', function($routeParams){
//check if search query string is set
if ($routeParams.search){
//do stuff here
}
});

Another way reading the paramters is using

$location.search()

Links

https://docs.angularjs.org/api/ngRoute/service/$routeParams