Implementing a Simple Application That Uses All Four Types of Services

In this example you will build constant, value, factory, and service services. The purpose is to give a chance to see how each can be implemented, as well as the perspective of using multiple types of services in your applications.

The code in Listing 10.1 shows an example of integrating value, constant, factory, and service services into a single module. The example is very basic and easy to follow. Notice that censorWords and repString are injected into and used in the factory and service definitions.

Lines 4–13 implement a factory service that returns a function that censors a string. Notice that line 26 calls the factory directly to censor the string.

Lines 14–25 implement ...

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.