Wednesday 5 November 2014

Angular Services vs Factories vs Providers

The following explanations were taking from various Angular docs, Misko code examples and StackOverflow posts.

What?

image
  • Service returns an instance of the actual function
  • Factory returns function’s return value
  • Provider returns the output of the function’s $get function

       

       

      How?

      When?

      Factory and Service are the most commonly used recipes. The only difference between them is that Service recipe works better for objects of custom type, while Factory can produce JavaScript primitives and functions.

      Factories are an example of the revealing module pattern.

      Providers have the advantage that they can be configured during module configuration phase.

      Under the hood

      Services, Factories as well as Values are all created under the hood using Providers.

      No comments:

      Post a Comment