Table of Contents

IT:AD:Angular.JS:HowTo:Understand/Values, Factories, Services, Providers

Summary

We've covered Views and Controllers, and made rudimentary stabs at providing data in the scope for them both to refer to.

Let's make things more resilient by moving data sources out of the controllers.

Notes

Angular has a couple of different ways of providing data:

Constants and Values

A Constant or Value is nothing more than a Key/Value defined at a module level, that can then be Dependency injected into controllers, etc.

Values:

Constants:

Factories

Factories are dynamic Values, in as much that they are just like Values, except that they are methods:

Services

Services will turn out to be the most used classes – at least in my apps.

Providers

Finally, providers.

Providers are much like Services, except where those are singletons, Providers are more like configurable service factories:

So if providers is more or less the same as services, bar more complicated factory creation, why bother? Because it can be made confirable:

Resources