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: number; title: string; author: string; publisher: string; }
The preceding code snippet shows a TypeScript class for Book, with properties such as id, title, author, and publisher. Now let us create a service named BookService...