-
-
Save Defcoq/4b8ef6256d86aae964386d8e5eb37cb6 to your computer and use it in GitHub Desktop.
This file contains 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 { HttpClient, HttpParams } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { environment } from 'src/environments/environment'; | |
import { Weather } from './meteo'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class MeteoService { | |
constructor(private http: HttpClient) { } | |
getWeather(city: string): Observable<Weather> { | |
const options = new HttpParams() | |
.set('units', 'metric') | |
.set('q', city) | |
.set('appId', environment.apiKey); | |
return this.http.get<Weather>(environment.apiUrl + | |
'weather', { params: options }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment