Skip to content

Instantly share code, notes, and snippets.

@talkingdotnet
Created April 7, 2018 10:02
Show Gist options
  • Save talkingdotnet/8b45418965d40a8d4f57585dc3d271c7 to your computer and use it in GitHub Desktop.
Save talkingdotnet/8b45418965d40a8d4f57585dc3d271c7 to your computer and use it in GitHub Desktop.
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'fetchdata',
templateUrl: './fetchdata.component.html'
})
export class FetchDataComponent {
public forecasts: WeatherForecast[];
public cacheForecasts: WeatherForecast[];
public summaries: any[];
constructor(http: Http, @Inject('BASE_URL') baseUrl: string) {
http.get(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => {
this.forecasts = result.json() as WeatherForecast[];
this.cacheForecasts = this.forecasts;
}, error => console.error(error));
http.get(baseUrl + 'api/SampleData/GetSummaries').subscribe(result => {
this.summaries = result.json() as any[];
}, error => console.error(error));
}
filterForeCasts(filterVal: any) {
if (filterVal == "0")
this.forecasts = this.cacheForecasts;
else
this.forecasts = this.cacheForecasts.filter((item) => item.summary == filterVal);
}
}
interface WeatherForecast {
dateFormatted: string;
temperatureC: number;
temperatureF: number;
summary: string;
}
interface Summary {
name: string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment