1
2import { Component } from "@angular/core";
3import { HttpClient } from "@angular/common/http";
4import { map, delay } from "rxjs/operators";
5
6@Component({
7 selector: "my-app",
8 templateUrl: "./app.component.html",
9 styleUrls: ["./app.component.css"]
10})
11export class AppComponent {
12 private apiURL = "https://api.github.com/";
13 public message: string = "Uninitialized";
14 public response;
15
16 constructor(private httpClient: HttpClient) {}
17
18 async fetchData() {
19 this.message = "Fetching..";
20 this.response = "";
21 this.response = await this.httpClient
22 .get<any>(this.apiURL)
23 .pipe(delay(1000))
24 .toPromise();
25 this.message = "Fetched";
26 }
27}
28