Created
March 4, 2018 17:04
-
-
Save talkingdotnet/981945e8d22e35f4a4c1138b6750cc29 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 { HttpClient } from '@angular/common/http'; | |
@Component({ | |
selector: 'app-fetch-data', | |
templateUrl: './fetch-data.component.html' | |
}) | |
export class FetchDataComponent { | |
public forecasts: WeatherForecast[]; | |
public cacheForecasts: WeatherForecast[]; | |
public summaries: any[]; | |
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) { | |
http.get<WeatherForecast[]>(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => { | |
this.forecasts = result; | |
this.cacheForecasts = result; | |
}, error => console.error(error)); | |
http.get<any[]>(baseUrl + 'api/SampleData/GetSummaries').subscribe(result => { | |
this.summaries = result; | |
}, 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