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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s