Skip to content

Instantly share code, notes, and snippets.

@zeptobook
Created December 15, 2018 15:05
Show Gist options
  • Save zeptobook/81111f7e86bbe9d3202cd10f740606b6 to your computer and use it in GitHub Desktop.
Save zeptobook/81111f7e86bbe9d3202cd10f740606b6 to your computer and use it in GitHub Desktop.
fetch-data.component.ts
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