Injectable services

Another key building block of Angular services. Following Angular's architecture, services are supposed to encapsulate business logic and application-wide states. Additionally, services are useful to bridge between different components that aren't necessarily a direct parent and child.

As this is your first services-related task, extract the categories data to an Angular service.

First, generate the CategoriesService service, as part of the CoreModule, by executing the following command:

ng generate service modules/core/services/categories

Afterward, the service is created in a file named categories.service.ts, containing the following content:

import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' ...

Get Hands-On Full-Stack Web Development with ASP.NET Core 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.