Home Ask Login Register

Developers Planet

Your answer is one click away!

Landeeyo February 2016

How to get value of REST style parameter in Angular?

I have an application in ASP.NET MVC. It use REST-style parameters. Address of one action is http://app/Resource/Action/Id.

In Angular we can access query strings using $location.search() or $routeParams.search or even $window.location.search. Though any of these methods can obtain query string parameters.

How can I access my Id parameter (without splitting window.location.pathname)?


Michele Ricciardi February 2016

In your route configuration you can do this:

$routeProvider. when('/:Resource/:Action/:Id', { templateUrl: 'partials/your-partial.html', controller: 'YourCtrl' })

you can then use $routeParams to access the properties you require as follows:

var resource = $routeParams.Resource; var action = $routeParams.Action; var id = $routeParams.Id;

Post Status

Asked in February 2016
Viewed 3,644 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life