HTTP

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:

  1. 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,    …  ],  …})
  1. 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 ...

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.