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..

fxck
  • 4,898
  • 8
  • 56
  • 94

2 Answers2

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();
Brian Lewis
  • 5,739
  • 1
  • 21
  • 28
  • That's not gonna work, it's gonna change the url, I only need it to return the changed url as a string.. – fxck Aug 27 '13 at 17:55
  • If you just need to read it, you could use $location.path() or $location.url() without any arguments. Perhaps I am missing something. – Brian Lewis Aug 27 '13 at 18:10
  • I guess you are looking for $location.absUrl(); – Brian Lewis Aug 27 '13 at 18:14
  • 3
    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? – fxck Aug 27 '13 at 18:27
  • 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: http://stackoverflow.com/a/12896408/36546 – PeterFromCologne Mar 24 '14 at 13:09
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

Community
  • 1
  • 1
AddieD
  • 138
  • 7