javascript - 错误: Unreachable code detected ionic 3 weather app

标签 javascript typescript ionic-framework visual-studio-code

好的,所以我正在按照 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/

相关文章:

javascript - 其他 html 中的 iframe 事件

javascript - Window.chrome 对象在 Electron App 中未定义

javascript - 将 Base64 图像文件 URI 转换为文件对象

jquery-ui - 将 Aurelia 与 Webpack 结合使用时找不到模块 'jquery-ui'

javascript - karma Jasmine : How to test ionicModal?

javascript - 如何使通知保持打开状态直到用户将其关闭?

typescript - 我如何 Object.assign 到 Typescript 中对象的子属性?

javascript - 如何为 Angular 中的某些特定 URL 应用不同的(整页)背景?

angularjs - 在 Ionic 中完全删除缓存

javascript - 如何以 Angular 显示多 map ?