Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the querystring in AngularJS

Tags:

After reading and processing a query-string value from the URL, for example

http://myurl.com/#/?foo=baa 

I can change the URL to

http://myurl.com/#/?foo= 

by using

$location.search('myQueryStringParameter', ''); 

How do I get rid of the query-string altogether (without explicit redirects or server side action and so on) so that only

http://myurl.com/#/ 

remains in the browser? It should be fairly simple, but I can't find any reference.

like image 608
Olaf Avatar asked Sep 16 '13 16:09

Olaf


2 Answers

You were close, you needed to set null

$location.search('myQueryStringParameter', null);  

From ng.$location documentation

If search is a string, then paramValue will override only a single search parameter. If paramValue is an array, it will set the parameter as a comma-separated value. If paramValue is null, the parameter will be deleted.

like image 170
toxaq Avatar answered Sep 26 '22 22:09

toxaq


Try this:

$location.url($location.path()) 

See documentation for more information.

like image 35
Buu Nguyen Avatar answered Sep 25 '22 22:09

Buu Nguyen