O'Reilly logo

Learning AngularJS by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the $location Service

The $location service provides a wrapper to the JavaScript window.location object. This makes the URL accessible in your AngularJS application. Not only can you get information about the URL, but you also can modify it, changing the location with a new URL or navigating to a specific hash tag.

To add the $location service to a controller or service, you simply need to inject it using the standard dependency injection methods. For example:

app.controller('myController', ['$scope', '$location',                                function($scope, location) {    . . .  }]);

Table 9.5 lists the methods that can be called on the $location service and describes their implementation.

Table 9.5 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required