Reputation: 1037
I am using Ionic 3, I am trying to connect to a api and my code is given below.
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map'
@Injectable()
export class WeatherProvider {
apikey = 'xxxxxxxxxxxxxxx';
url;
constructor(public http: HttpClient) {
console.log('Hello WeatherProvider Provider');
this.url= 'http://api.wunderground.com/api/'+this.apikey+'/conditions/q';
}
getWeather(city, state){
return this.http.get(this.url+'/'+state+'/'+city+'.json')
.map(res => res.json());
}
}
I know the error, that is with this code .map(res => res.json());
Here is the error log
Typescript Error Property 'json' does not exist on type 'Object'.
src/providers/weather/weather.ts return this.http.get(this.url+'/'+state+'/'+city+'.json') .map(res => res.json()); }
Ionic Framework: 3.9.2 Ionic App Scripts: 3.1.9 Angular Core: 5.2.10 Angular Compiler CLI: 5.2.10 Node: 9.2.1 OS Platform: Linux 4.13 Navigator Platform: Linux x86_64 User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Give me a solution please
Upvotes: 0
Views: 203
Reputation: 222552
You do not need to call .json()
with httpClient
because the response is JSON by default
return this.http.get(this.url+'/'+state+'/'+city+'.json')
.map(res => res);
Upvotes: 1