1

I have a pretty good understanding of Angular, but I am starting to dabble with Typescript and Angular.

What is the difference between a factory, service and provider as far as setting up the module.

Example:

var app = angular.module('app', []);

//Setting up a factory
app.factory('TestFactory', ['$http', TypescriptModule.TestFactory]);
// Or
app.factory('TestFactory', ['$http', ($http) => new TypescriptModule.TestFactory($http)]);

//Setting up a service
app.service('TestService', ['$scope', TypescriptModule.TestService]);
// Or
app.service('TestService', ['$scope', ($scope) => new TypescriptModule.TestService($scope)]);

I guess what I am getting to is that you have to instantiate a factory, whereas a service's constructor is called for you?

What about providers? And while we are on the subject, what about constants, values, etc.?

Sam
  • 15,336
  • 25
  • 85
  • 148
  • http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory – PSL Sep 30 '14 at 03:44
  • @PSL - It seems a bit different when using Typescript, or am I wrong? – Sam Sep 30 '14 at 03:46
  • I think you can get your answer [here][1] Service vs provider vs factory. [1]: http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory – A H K Sep 30 '14 at 03:47
  • 2
    @Sam Not really, concepts remain the same. Typescript just provides the syntactic sugars to write them in a more typed manner. – PSL Sep 30 '14 at 03:49
  • @PSL - So why use a service over a factory or vise-versa? – Sam Sep 30 '14 at 03:54

0 Answers0