3

Is there a way to do it?

If the current url is say..

/table?sort=activity and I wanted to update it right away, I'd do

$location.url(null, {sort: 'something'})

but what if I wanted to get back the updated url /table?sort=something without updating it?

All the $location functions seems to change the url right away when used with parameters..

2 Answers 2

1

For completeness thought I'd share this SO question. The question and answers are old but there's a good chance the answer still applies.

How to programmatically create URLs with AngularJS

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

Comments

1

What you are looking for is $location.search()

It would look something like this:

$location.search({sort: 'something'});

Update based on comments

According to the Developers Guide, you can use the following to read the URL:

$location.absUrl();

To read the hash:

$location.path();

To read the query params:

$location.search();

5 Comments

That's not gonna work, it's gonna change the url, I only need it to return the changed url as a string..
If you just need to read it, you could use $location.path() or $location.url() without any arguments. Perhaps I am missing something.
I guess you are looking for $location.absUrl();
Not really either :) I'm looking for something that's gonna "compile" the url for me, exactly what $location.search({sort: 'something'}) does, but instead of directly changing the url, I just want it to return the url as a string.. any clearer now?
If I get you right, you need a URL builder functionality. not actually changing the URL but constructing a new one. Maybe this SO answer helps you: stackoverflow.com/a/12896408/36546

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.