Hinzufügen von API -Anfrage
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<ApiResponse>("http://quotes.stormconsultancy.co.uk/random.json").subscribe(data=>{ // Succesful API request this.quote = new Quote(data.author, data.quote) }) }}
Elated Elephant