Implementing ngOnInit

Now that we know what we did wrong, we can fix our issue by properly implementing a ngOnInit hook within our QuizListComponent class.

Open the quiz-list.component.ts file and add the following code (new/updated lines are highlighted):

import { Component, Inject, Input, OnInit } from "@angular/core";import { HttpClient } from "@angular/common/http";@Component({    selector: "quiz-list",    templateUrl: './quiz-list.component.html',    styleUrls: ['./quiz-list.component.css']})export class QuizListComponent implements OnInit {    @Input() class: string;    title: string;    selectedQuiz: Quiz;    quizzes: Quiz[];    http: HttpClient;    baseUrl: string;    constructor(http: HttpClient,         @Inject('BASE_URL') baseUrl: string) {        this.http = http; this.baseUrl ...

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.