Services

For now, we have reviewed two out of four of the building blocks of Angular 2. The remaining two are services and directives. The next block we are going to review services. Services are classes with a unique purpose that shall be, as much as possible, cohesive in the sense that they provide a narrow and well-defined service to other parts of the application. From a design point of view, what could be nice for our Floyd triangle application is to have the content of the FloydComponent.onClick method inside a service. Indeed, the computation of the floydString string does not have its place in a component managing the view.

A component should only be in charge of the user experience—binding properties to a template—and nothing else. ...

Get Angular Design Patterns 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.