好的,所以我正在按照 ionic 3 上的遍历媒体教程进行操作,当我到达创建提供程序的部分时,我收到错误消息,指出此处检测到无法访问的代码:
.map((res: Response) => res.json() );
它还在 typescript 上说
cannot find the name 'map' did you mean 'Map'?
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
@Injectable()
export class WeatherProvider {
apiKey = "89cca14f4ffcd27d602ad5e587f8e17f";
url;
constructor(public http: HttpClient) {
console.log('Hello WeatherProvider Provider');
this.url = "api.openweathermap.org/data/2.5/weather?q=";
}
getWeather(city, country){
return this.http.get(this.url+city+','+country);
.map((res: Response) => res.json() );
}
}
最佳答案
getWeather()
中的 return 语句导致 .map()
无法访问。您应该将 return 语句设置为函数中的最后一个语句。
关于javascript - 错误: Unreachable code detected ionic 3 weather app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53289111/