rohit raut rohit raut - 3 months ago 18
AngularJS Question

How to get id from url in angularjs

I am having trouble to get Id from url as follows:
http://user.com/nrms/classified/#42/

How can I get 42 from this url in angularjs? Is there any way in angularjs $location to fetch the same?.

Answer
var href = window.location.href;

$scope.id = href.substr(href.lastIndexOf('/') + 1).replace('#', '');

if your url is: http://user.com/nrms/classified/#42

Then you get output, 42
Comments