Parses the browser location url and makes it available to your application.
Any changes to the url are reflected into $location
service and changes to
$location
are reflected in the browser location url.
Notice that using browser's forward/back buttons changes the $location.
Updates the location object. Does not immediately update the browser Browser is updated at the end of $digest()
Does not immediately update the browser. Instead the browser is updated at the end of $eval() cycle.
$location.update('http://www.angularjs.org/path#hash?search=x'); $location.update({host: 'www.google.com', protocol: 'https'}); $location.update({hashPath: '/path', hashSearch: {a: 'b', x: true}});
href – {string|Object} –
Full href as a string or object with properties
Updates the hash fragment part of the url.
path – {string|Object} –
A hashPath or hashSearch object
search(optional) – {Object} –
A hashSearch object
The full URL of the current location.
The protocol part of the URL (e.g. http or https).
The host name, ip address or FQDN of the current location.
The port number of the current location (e.g. 80, 443, 8080).
The path of the current location (e.g. /myapp/inbox).
Map of query parameters (e.g. {user:"foo", page:23}).
The fragment part of the URL of the current location (e.g. #foo).
Similar to path
, but located in the hash
fragment
(e.g. ../foo#/some/path => /some/path).
Similar to search
but located in hash
fragment (e.g. .../foo#/some/path?hashQuery=param => {hashQuery: "param"}).
<div ng:init="$location = $service('$location')"> <a id="ex-test" href="#myPath?name=misko">test hash</a>| <a id="ex-reset" href="#!/api/angular.service.$location">reset hash</a><br/> <input type='text' name="$location.hash" size="30"> <pre>$location = {{$location}}</pre> </div>
it('should initialize the input field', function() { expect(using('.doc-example-live').input('$location.hash').val()). toBe('!/api/angular.service.$location'); }); it('should bind $location.hash to the input field', function() { using('.doc-example-live').input('$location.hash').enter('foo'); expect(browser().location().hash()).toBe('foo'); }); it('should set the hash to a test string with test link is presed', function() { using('.doc-example-live').element('#ex-test').click(); expect(using('.doc-example-live').input('$location.hash').val()). toBe('myPath?name=misko'); }); it('should reset $location when reset link is pressed', function() { using('.doc-example-live').input('$location.hash').enter('foo'); using('.doc-example-live').element('#ex-reset').click(); expect(using('.doc-example-live').input('$location.hash').val()). toBe('!/api/angular.service.$location'); });