Skip to content

Commit

Permalink
feat(weather): Add weather component
Browse files Browse the repository at this point in the history
  • Loading branch information
funami-dev committed Oct 16, 2018
1 parent 09c9718 commit aecf33c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 18 deletions.
40 changes: 31 additions & 9 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -75,16 +80,26 @@
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": ["src/styles.css"],
"styles": [
"src/styles.css"
],
"scripts": [],
"assets": ["src/favicon.ico", "src/assets"]
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
Expand All @@ -109,11 +124,18 @@
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": ["**/node_modules/**"]
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "Kourou"
}
"defaultProject": "Kourou",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --open",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
Expand Down
8 changes: 7 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<div>
Temp: {{ weatherData.main.temp }}°
<div>Temp:
<span *ngIf="weatherData;else loading">
{{ weatherData.main.temp }}
</span>
<ng-template #loading>lädt</ng-template>°
</div>

</div>
13 changes: 8 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { WeatherService } from './weather.service';
import { Weatherdata } from '../interfaces/WeatherData';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private weatherService: WeatherService) {}
export class AppComponent implements OnInit {
public weatherData: Weatherdata[] = [];

weatherData = {};
constructor(private weatherService: WeatherService) {}

getWeatherData(): void {
this.weatherService.getWeatherData().subscribe(data => (this.weatherData = { ...data }));
this.weatherService.getWeatherData().subscribe(data => {
this.weatherData = data;
});
}

ngOnInit() {
Expand Down
7 changes: 5 additions & 2 deletions src/app/weather.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Weatherdata } from '../interfaces/WeatherData';
import { environment } from '../environments/environment';

@Injectable({
Expand All @@ -9,8 +11,9 @@ export class WeatherService {
constructor(private http: HttpClient) {}
WEATHER_API_URL = environment.WEATHER_API_URL;

public getWeatherData() {
public getWeatherData(): Observable<any[]> {
const { prefix, base, cityId, key } = this.WEATHER_API_URL;
return this.http.get(`${prefix}${base}?id=${cityId}&appid=${key}`);
const _url = `${prefix}${base}?id=${cityId}&appid=${key}`;
return this.http.get<Weatherdata[]>(_url);
}
}

0 comments on commit aecf33c

Please sign in to comment.