$location
ng
The $location service parses the URL in the browser address bar (based on the window.location) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.
The $location service:
For more information see Developer Guide: Angular Services: Using $location
This method is getter / setter.
Return path of current url when called without any parameter.
Change path when called with parameter and return $location
.
Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.
Param | Type | Details |
---|---|---|
path (optional) | string | New path |
string | path |
If called, all changes to $location during current $digest
will be replacing current history
record, instead of adding new one.
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
.
Param | Type | Details |
---|---|---|
search | stringObject.<string>Object.<Array.<string>> | New search params - string or hash object. Hash object may contain an array of values, which will be decoded as duplicates in the url. |
paramValue (optional) | string | If |
string | search |
This method is getter / setter.
Return url (e.g. /path?a=b#hash
) when called without any parameter.
Change path, search and hash, when called with parameter and return $location
.
Param | Type | Details |
---|---|---|
url (optional) | string | New url without base prefix (e.g. |
replace (optional) | string | The path that will be changed |
string | url |