javascriptangularjs

How to get last part of URL, ignoring any GET parameters?


I'm expecting URLs in this for:

/user/username

but end users can also add whatever get parameters they want, like so:

/user/username?foo=bar

With that said, using AngularJS, what's the preferred way for me to get just the username (which appears after /user/) without anything else after it?


Solution

  • You should use the $location service and its .path() method, then use a regular split() and indexing.