Created
December 15, 2018 15:05
-
-
Save zeptobook/81111f7e86bbe9d3202cd10f740606b6 to your computer and use it in GitHub Desktop.
fetch-data.component.ts
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 } from '@angular/core'; | |
import { HttpClient } from '@angular/common/http'; | |
@Component({ | |
selector: 'app-fetch-data', | |
templateUrl: './fetch-data.component.html' | |
}) | |
export class FetchDataComponent { | |
public forecasts: WeatherForecast[]; | |
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) { | |
http.get<WeatherForecast[]>(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => { | |
this.forecasts = result; | |
}, error => console.error(error)); | |
} | |
} | |
interface WeatherForecast { | |
dateFormatted: 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