0

I have a url which looks like below

http://localhost:8080/test#/users/list

When I use the below:-

$location.url() gives me -> "users/list"
$location.path() gives me -> "users/list"
$location.absUrl() gives me ->"http://localhost:8080/test#/users/list" the entire url
$location.host() gives me-> "localhost"

Is there any way I can get just :- http://localhost:8080/test#/ or even test#/ ?

I could get the entire url and split it on /, but was trying to find if there was another way.

3
  • 1
    $location.absUrl().replace($location.path(), '')? Commented Dec 27, 2019 at 15:39
  • That would work but when the url changes to something like :-http://localhost:8080/test?someid=123&debug=true#/users/list it would give me http://localhost:8080/test?someid=123&debug=true# rather than http://localhost:8080/test @HereticMonkey Commented Dec 27, 2019 at 15:50
  • That URL isn't really something you would get in a typical AngularJS application. Generally the URL before the # stays constant, since AngularJS is taking care of the routing. If you're not using AngularJS for routing, $location may be of less use to you. Commented Dec 27, 2019 at 16:00

1 Answer 1

1

The code can use:

$window.location.pathname

With http://localhost:8080/test#/users/list, it returns /test

For more information, see

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.