The categories are currently hardcoded values; however, they should be loaded from the RESTful API and through HTTP calls. Angular provides its own abstraction for HTTP, in the form of a service that you can use when necessary.
Next, let's use Angular's HttpClient service to load the categories from the backend RESTful API:
- Import HttpClientModule into app.module.ts to make the HttpClient service available to the entire app:
…import { HttpClientModule } from '@angular/common/http';…@NgModule({ … imports: [ HttpClientModule, … ], …})
- Use the HttpClient service in CategoriesService as follows. If the HTTP address differs in your setup, then make sure to change it accordingly:
import { Injectable } from '@angular/core';import { HttpClient ...