angular.service.$location

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

Description

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.

Dependencies

Methods

Properties

Example

   <div ng:init="$location = $service('$location')">
     <a id="ex-test" href="#myPath?name=misko">test hash</a>|
     <a id="ex-reset" href="#!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').element('input[name=$location.hash]').val()).
       toBe('!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').element('input[name=$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').element('input[name=$location.hash]').val()).
       toBe('!angular.service.$location');
   });