Services, Provider, Factory in AngularJS

Services:

Singleton objects that carry out the tasks necessary to support your application’s functionality.

In built Angular services starts with $. for example. $http, $location, $route, $filter etc..

There are three functions for creating generic services:

Provider ( name, object or constructor )

A configurable service with complex creation logic. if you pass an pbject it should have a function named $get that returns an instance of service. Otherwise Angular assumes you’ve passed a constructor that when called, creates and instance.

Factory (name, $get function() {} )

A non-configurable service with complex creation logic. Where you specify a function that when called returns the service instance.

Factory ( name, Constructor )

A non-configurable service with simple creation logic

Leave a Reply