Example

Note that the $location service is passed in to the controller
as an argument. In order to use the service in the controller, it must be
defined as a dependency.

Why use Services?

For many services, like the $location service, it seems like you
could use objects that are already in the DOM, like the window.location
object, and you could, but it would have some limitations, at least for your
AngularJS application.

AngularJS constantly supervise your application, and for it to handle changes
and events properly, AngularJS prefers that you use the $location
service instead of the window.location object.

The $http Service

The $http service is one of the most common used services in AngularJS
applications. The service makes a request to the server, and lets your
application handle the response.