Search code examples
angularjsangularjs-serviceangularjs-factory

AngularJS: Factory and Provider Scenarios


I'm learning AngularJS and I noticed that A Factory is a short-hand for a Provider. Can you tell me specific scenarios where I should/must use a Provider instead of a Factory? The codes stays much more readable if use a Factory method instead of the provider.


Solution

  • A Provider is necessary when the provider itself has methods that you want the user of your service to call during the configuration phase of the application.

    See for example the $location service: it has a $locationProvider which allows setting it to html5 mode, while the application is being configured (using module.config()).