Services are singleton objects. In other words, It’s javascript function to perform a specific task. Angular allow us to use these services with controllers, service, filter or directive.

Whenever we want to use service with the above components, we will have to inject the service name along with the component. By doing so, component ask angular to load that particular service in the application. This method of injecting service is called dependency injection.

To know more about the complete collection of Service lists, please visit Complete lists of Services.

How to use Service with Components?

To use a service, you will have to add it as a dependency with a component  such as controller, filter  or service. To add a service with component, you have to pass it as an argument.

For Example:

 App.controller(“controllerName”, function($scope, $service))

{

 

});

 

In the above example we injected our $service along with the controller.

 

Types of Services:

There are 2 types of Services are available in AngulrJS,

  1. Inbuilt Service
  2. Custom Service

To view the complete information about Service and Factory in AngularJS, Please visit our Blog.