Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

Adding API request

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)    })  }}
Source by moringaschool.instructure.com #
 
PREVIOUS NEXT
Tagged: #Adding #API #request
ADD COMMENT
Topic
Name
6+8 =