Skip to content

update locationSearch to mimic the $location.search API #5

@JustinBeaudry

Description

@JustinBeaudry

search(search, [paramValue]);

This method is getter / setter.

Return search part (as object) of current url when called without any parameter.

Change search part when called with parameter and return $location.

// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var searchObject = $location.search();
// => {foo: 'bar', baz: 'xoxo'}
// set foo to 'yipee'
$location.search('foo', 'yipee');
// $location.search() => {foo: 'yipee', baz: 'xoxo'}

Parameters

search String | Object.<string> | Object.<Array.<string>>

New search params - string or hash object.

When called with a single argument the method acts as a setter, setting the search component of $location to the specified value.

If the argument is a hash object containing an array of values, these values will be encoded as duplicate search parameters in the url.

paramValue (optional) String | Number | Array.<string> | Boolean

If search is a string or number, then paramValue will override only a single search property.

If paramValue is an array, it will override the property of the search component of $location specified via the first argument.

If paramValue is null, the property specified via the first argument will be deleted.

If paramValue is true, the property specified via the first argument will be added with no value nor trailing equal sign.

Returns

Object
If called with no arguments returns the parsed search object. If called with one or more arguments returns $location object itself.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions