【发布时间】:2018-10-21 14:02:05
【问题描述】:
我正在使用 Ionic 3,我正在尝试连接到 api,我的代码如下所示。
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());
}
}
我知道错误,就是这段代码 .map(res => res.json());
这是错误日志
Typescript 错误属性“json”在类型“Object”上不存在。
src/providers/weather/weather.ts return this.http.get(this.url+'/'+state+'/'+city+'.json') .map(res => res.json()); }Ionic 框架:3.9.2 Ionic App 脚本:3.1.9 Angular Core:5.2.10 Angular 编译器 CLI:5.2.10 节点:9.2.1 操作系统平台:Linux 4.13 导航平台:Linux x86_64 用户代理:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, 像 Gecko) Chrome/63.0.3239.132 Safari/537.36
请给我一个解决方案
【问题讨论】: