Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$location.search does not remove query args when pass in an object #6565

Closed
wangshijun opened this issue Mar 6, 2014 · 2 comments
Closed

Comments

@wangshijun
Copy link

When the following code is used to remove query args from location url, it worked as expected:

$location.search('sid', null);
$location.search('time', null);
$location.search('sign', null);

But, the following code does not work as expected:

$location.search({
    sid: null,
    time: null,
    asign: null
});

Please correct if this is the correct behavior of $location.search
@vojtajina vojtajina self-assigned this Mar 6, 2014
@vojtajina vojtajina added this to the Backlog milestone Mar 6, 2014
@vojtajina
Copy link
Contributor

That's a bug, I think setting an object should behave the same as setting a single param.

It's this code:

search: function(search, paramValue) {
switch (arguments.length) {
case 0:
return this.$$search;
case 1:
if (isString(search)) {
this.$$search = parseKeyValue(search);
} else if (isObject(search)) {
this.$$search = search;
} else {
throw $locationMinErr('isrcharg',
'The first argument of the `$location#search()` call must be a string or an object.');
}
break;
default:
if (isUndefined(paramValue) || paramValue === null) {
delete this.$$search[search];
} else {
this.$$search[search] = paramValue;
}
}
this.$$compose();
return this;
},
, we need to check the object for nulls/undefineds, the same way we do when setting a single property.

@vojtajina vojtajina removed their assignment Mar 6, 2014
SekibOmazic added a commit to SekibOmazic/angular.js that referenced this issue Mar 6, 2014
Query args will be removed from $location search object if they are passed in as null or undefined object properties

closes angular#6565
SekibOmazic added a commit to SekibOmazic/angular.js that referenced this issue Mar 6, 2014
Query args will be removed from $location search object if they are passed in as null or undefined object properties

closes angular#6565
@SekibOmazic
Copy link
Contributor

Commit f3f3c88 is more elegant but uses Object.keys() which is not supported by IE8. The commit b7a926d uses for..in and hasOwnProperty() which works for all browsers.

IgorMinar pushed a commit that referenced this issue Jul 1, 2014
Query args will be removed from $location search object if they are passed in as null or undefined object properties

Closes #6565
ckknight pushed a commit to ckknight/angular.js that referenced this issue Jul 16, 2014
Query args will be removed from $location search object if they are passed in as null or undefined object properties

Closes angular#6565
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants