Understanding AngularJS Services

AngularJS services are singleton objects, which means only one instance is ever created. The intent of a service is to provide a concise bit of code that performs specific tasks. A service can be as simple as providing a value definition or as complex as providing full HTTP communication to a web server.

A service provides a container for reusable functionality that is readily available to AngularJS applications. Services are defined and registered with the dependency injection mechanism in AngularJS. This enables you to inject services into modules, controllers, and other services.

Note

Chapter 3, “Understanding AngularJS Application Dynamics,” discusses dependency injection. You should read that chapter, if ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.