0

https://www.aurorasolutions.io/blog/angularjs-service-types-with-examples/ - This article explains various types of services in angularjs such as Service, factory, provider, constant and value. Then I was clear with the difference between various services in angularjs. Then I read this article http://blog.xebia.com/differences-between-providers-in-angularjs/ which explains the difference between various types of providers in angularjs such as service, factory, provider, constant, value and decorators.

This is confusing for me.

What is the differnce between Providers and services, which have the same methods with same way of functioning?

When should I use types of service methods and provider methods?

What is the need of implementing the same methods in different ways?

  • You must have missed this guide https://docs.angularjs.org/guide/providers ? Long story short different syntactic sugar for defining things that the injector can get, some of them like "raw providers" can be used in the .config stage and therefore can have some setup before they are used in run or anywhere else other providers can be injected. The 'value' is convenient if you need some data object like a constant you want to inject various places or a static list, factory or service work mostly the same aside from the instantiation with the service. – shaunhusain Jan 12 '18 at 10:48
  • service, factory, provider are [essentially identical](https://blog.thoughtram.io/angular/2015/07/07/service-vs-factory-once-and-for-all.html#the-difference-between-services-and-factories) (with slightly different syntax). – Aleksey Solovey Jan 12 '18 at 10:52
  • Under the hood the .service actually calls .factory but just instantiates a new instance of the function/object defined by the .service see the table at the bottom of the linked providers page for a quick reference of which provider types can be used in which contexts. https://github.com/angular/angular.js/blob/master/src/auto/injector.js#L791 can also see factory calls provider here https://github.com/angular/angular.js/blob/master/src/auto/injector.js#L785 but if you want to have properties on the provider modified in config then you would just use `.provider` – shaunhusain Jan 12 '18 at 10:52

0 Answers0