Improve this Doc View Source $location
- $locationProvider
- service in module 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:
- Exposes the current URL in the browser address bar, so you can- Watch and observe the URL.
- Change the URL.
 
- Synchronizes the URL with the browser when the user- Changes the address bar.
- Clicks the back or forward button (or clicks a History link).
- Clicks on a link.
 
- Represents the URL object as a set of methods (protocol, host, port, path, search, hash).
For more information see Developer Guide: Using $location
Dependencies
Methods
-  absUrl();This method is getter only. Return full url representation with all segments encoded according to rules specified in RFC 3986. Returnsstringfull url 
-  url([url]);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.ParametersParam Type Details url (optional)stringNew url without base prefix (e.g. /path?a=b#hash)Returnsstringurl 
-  protocol();This method is getter only. Return protocol of current url. Returnsstringprotocol of current url 
-  host();This method is getter only. Return host of current url. Returnsstringhost of current url. 
-  port();This method is getter only. Return port of current url. ReturnsNumberport 
-  path([path]);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. ParametersParam Type Details path (optional)stringnumberNew path Returnsstringpath 
-  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'); // => $locationParametersParam 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 searchcomponent of$locationto 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>booleanIf searchis a string or number, thenparamValuewill override only a single search property.If paramValueis an array, it will override the property of thesearchcomponent of$locationspecified via the first argument.If paramValueisnull, the property specified via the first argument will be deleted.If paramValueistrue, the property specified via the first argument will be added with no value nor trailing equal sign.ReturnsObjectIf called with no arguments returns the parsed searchobject. If called with one or more arguments returns$locationobject itself.
-  hash([hash]);This method is getter / setter. Return hash fragment when called without any parameter. Change hash fragment when called with parameter and return $location.ParametersParam Type Details hash (optional)stringnumberNew hash fragment Returnsstringhash 
-  replace();If called, all changes to $location during current $digestwill be replacing current history record, instead of adding new one.
Events
-  $locationChangeStartBroadcasted before a URL will change. This change can be prevented by calling preventDefaultmethod of the event. See$rootScope.Scopefor more details about event object. Upon successful change $locationChangeSuccess is fired.Type:broadcastTarget:root scope
-  $locationChangeSuccessBroadcasted after a URL was changed. Type:broadcastTarget:root scope
    © 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
    https://code.angularjs.org/1.2.32/docs/api/ng/service/$location