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 Injection, by adding an attribute variable to the constructor:

[...]

constructor(private activatedRoute: ActivatedRoute,
private router: Router,
private http: HttpClient) {


}

[...]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.27.72