Created
May 15, 2020 19:37
-
-
Save manoj-choudhari-git/52f50c7d778ff04b33f10d9a3248015e to your computer and use it in GitHub Desktop.
Fetch data component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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