Created
April 7, 2018 10:02
-
-
Save talkingdotnet/8b45418965d40a8d4f57585dc3d271c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { 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