Skip to content

Instantly share code, notes, and snippets.

@Defcoq
Created December 12, 2021 13:00
Show Gist options
  • Save Defcoq/4b8ef6256d86aae964386d8e5eb37cb6 to your computer and use it in GitHub Desktop.
Save Defcoq/4b8ef6256d86aae964386d8e5eb37cb6 to your computer and use it in GitHub Desktop.
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