Using the $location service

AngularJS provides an abstraction layer over URLs (and their behavior) in the form of the $location service. This service masks the difference between the hashbang and the HTML5 URL modes allowing us, application developers, to work with a consistent API regardless of the browser and the mode being used. But the $location service does more heavy lifting, by providing the following functions:

  • Provides convenient, clean API to easily access different parts of the current URL (protocol, host, port, path, query parameters, and so on)
  • Lets us to programmatically manipulate different parts of the current URL and have those changes reflected in the browser's address bar
  • Allows us to easily observe changes in different components ...

Get Mastering Web Application Development with AngularJS now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.