Adding API request

The solution for “Adding API request” can be found here. The following code will assist you in solving the problem.

import { Component, OnInit } from ‘@angular/core’;import { HttpClient } from ‘@angular/common/http’;…import { Quote } from ‘../quote-class/quote’;….export class GoalComponent implements OnInit {    goals:Goal[];  alertService:AlertService;  quote:Quote;….  constructor(goalService:GoalService, alertService:AlertService, private http:HttpClient) {    this.goals = goalService.getGoals()    this.alertService = alertService;  }  ngOnInit() {    interface ApiResponse{      author:string;      quote:string;    }    this.http.get(“”).subscribe(data=>{      // Succesful API request      this.quote = new Quote(, data.quote)    })  }}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

inline scripts encapsulated in