Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 15, 2020 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/52f50c7d778ff04b33f10d9a3248015e to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/52f50c7d778ff04b33f10d9a3248015e to your computer and use it in GitHub Desktop.
Fetch data component
import { Component, Inject, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-fetch-data',
templateUrl: './fetch-data.component.html'
})
export class FetchDataComponent implements OnInit {
public forecasts: WeatherForecast[];
constructor(private readonly http: HttpClient) {
}
ngOnInit(): void {
const apiUrl = "https://localhost:44379/weatherforecast";
this.http.get<WeatherForecast[]>(apiUrl).subscribe(result => {
this.forecasts = result;
}, error => console.error(error));
}
}
interface WeatherForecast {
date: string;
temperatureC: number;
temperatureF: number;
summary: string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment