Adding the HttpClient

So far, so good; now we need to replace that to-do with a working code that will get the quiz from the .NET Core QuizController. We can easily do that with the HttpClient service, just like we did to get the quiz array in the QuizListController a while ago. In order to use it, we need to add the required import reference to the top of the quiz.controller.ts file:

import { Component, Inject } from "@angular/core";import { ActivatedRoute, Router } from "@angular/router";import { HttpClient } from "@angular/common/http";[...]

While we were there, we also added the Inject decorator in line 1, as we will use it in a few.

The next step is to have the HttpClient available somewhere. As usual, we can achieve that through Dependency ...

Get ASP.NET Core 2 and Angular 5 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.