Creating a service

Application-specific or business logic functions, such as persisting application data, logging the errors, file storage, and so on, should be delegated to services, and the components should consume the respective services to deal with the appropriate business or application-specific logics:

Let us create a simple service called BookService that deals with fetching the collection of books available in the source. The source may be data returned from a web API service or a JSON file.

First, let us create a Book model to persist the domain object value. The code snippet of a Book class is shown here:

 export class Book { id: ...

Get Expert Angular 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.