0

What is different between myApp.factory and myApp.service in angular web application. please explain use of both in logical way.

Dileep Kheni
  • 882
  • 1
  • 7
  • 29
  • possible duplicate of [angular.service vs angular.factory](http://stackoverflow.com/questions/14324451/angular-service-vs-angular-factory) – Jayram Jan 22 '15 at 07:04

1 Answers1

0

Source:- https://stackoverflow.com/a/15666049/1632286

From the AngularJS mailing list I got an amazing thread that explains service vs factory vs provider and their injection usage. Compiling the answers:

Services

Syntax: module.service( 'serviceName', function ); Result: When declaring serviceName as an injectable argument you will be provided with an instance of the function. In other words new FunctionYouPassedToService().

Factories

Syntax: module.factory( 'factoryName', function ); Result: When declaring factoryName as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory.

Providers

Syntax: module.provider( 'providerName', function ); Result: When declaring providerName as an injectable argument you will be provided with ProviderFunction().$get(). The constructor function is instantiated before the $get method is called - ProviderFunction is the function reference passed to module.provider.

Community
  • 1
  • 1
squiroid
  • 13,809
  • 6
  • 47
  • 67