user1386906
user1386906

Reputation: 1179

Get location path plus anchor link in AngularJS

I want to use the location path and anchor link (a link to an element in the page). So i can use the value in my controller

So i have a path in my browser like so:

/atomics#icons 

/atomics is the route and #icons is a link inside the page to an element When i use $location.path() in my controller I only get /atomics, i want to get #icons value aswell. Is this possible?

Upvotes: 1

Views: 3897

Answers (2)

pv1
pv1

Reputation: 534

To redirect to /atomics#icons from another location you have to give both below commands:

$location.hash('icons');
$location.path('/atomics');

Upvotes: 0

Martin
Martin

Reputation: 8866

Assuming you have an URL like /atomics#icons you can use the following $location functions to extract parts of it:

In case you want to extract querystring values you can also use $location.search().

Official $location documentation.

Upvotes: 4

Related Questions