O'Reilly logo

AngularJS Services by Jim Lavin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Services, factories, and providers

As we have discussed so far, a service is a single instance of an object, function, or value that you can leverage across the various components of your application. When you inject a service into an application, the $inject service first looks to check if an instance of the service already exists. If it does, the $inject service returns the existing instance. If it does not, the $inject service creates a new instance of the service and returns it.

With this in mind, we can use one of five different module-definition methods to create our service. The first two are best for static values, configuration values, and models and the rest are best for defining services based on how they are constructed or used.

The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required