Struggling with a REST call in my http.service.ts file while working with Angular version 7 and RxJS. The goal is to extract the "cod" value from a JSON response obtained from a REST call to the openweather API. However, when I add map() to extract the desired value, it doesn't work, only without map() it functions. What am I overlooking?
Here's my code snippet:
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { HttpClient } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
const API_URL = environment.apiURL;
const API_KEY = environment.apiKey;
@Injectable({
providedIn: 'root'
})
export class HttpService {
constructor(private http: HttpClient) { }
public getWeather() {
return this.http.get(API_URL + '?q=London,us&APPID=' + API_KEY).pipe(map(r => { return r; })).subscribe(value => {
}, catchError(error => {
return throwError(error);
}))
}
}