francoisromain francoisromain - 1 year ago 106
AngularJS Question

with $ how to remove a parameter from the url when it's null

to set an url

the search parameter which is passed to the
is set by a form. selecting and deselecting an element causes some parameters value to be "null" and so the url looks like this :

so i would like to remove those "null" parameters from the url. In the documentation, there is a "paramValue" which can be passed as a second parameters to .search(search, paramValue) : If the value is
, the parameter will be deleted.

but i can't make this work… any suggestion ?

edit: here is a solution based on @BKM explanation

to remove every parameters which are
, it's necessary to loop through all of them and test each one, like this :

for (var i in search) {
if (!search[i]) $, null);

Answer Source

Using the $location service, you can remove the search param by assigning it a null value:

In the case when your parameter is null, in your case 'parameter' you can remove it from the url by assigning it a null value like;

$'parameter', null);

Hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download