rohit raut rohit raut - 1 year ago 78
AngularJS Question

How to get id from url in angularjs

I am having trouble to get Id from url as follows:

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

Answer Source
var href = window.location.href;

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

if your url is:

Then you get output, 42