$location.search()

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

Param Type Details
search stringObject.<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)
stringNumberArray.<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.

doc_AngularJS
2016-03-29 16:10:30
Comments
Leave a Comment

Please login to continue.