Angular 6:获取错误模块“rxjs/add/operator/map"的地方类型“Observable<Response>"上不存在另一个错误“map" [英] Angular 6 : where getting error module "rxjs/add/operator/map" and another error 'map' does not exist on type 'Observable<Response>'

查看:23
本文介绍了Angular 6:获取错误模块“rxjs/add/operator/map"的地方类型“Observable<Response>"上不存在另一个错误“map"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Angular 6 时遇到两个错误 -

I am using Angular 6 where I am getting two errors -

  1. ./src/app/app/img/img.service.ts 中的错误找不到模块:错误:无法解析/Users/user/Projects/A4/imageSearch/src/app/app/img"中的rxjs/add/operator/map"

  1. ERROR in ./src/app/app/img/img.service.ts Module not found: Error: Can't resolve 'rxjs/add/operator/map' in '/Users/user/Projects/A4/imageSearch/src/app/app/img'

src/app/app/img/img.service.ts(21,9) 中的错误:错误 TS2339:Observable"类型上不存在属性map".

ERROR in src/app/app/img/img.service.ts(21,9): error TS2339: Property 'map' does not exist on type 'Observable'.

推荐答案

我在使用 rxjs map 操作符时遇到了类似的问题.目前我使用的是 Angular 6.要知道您使用的是哪个版本:

I faced similar problem with rxjs map operator. Currently I'm using Angular 6. To know which version you are using:

ng --version

ng -v

如果您还使用 angular 6,请查看 https://www.academind.com/learn/javascript/rxjs-6-what-c​​hanged/

If you are also using angular 6, then please checkout https://www.academind.com/learn/javascript/rxjs-6-what-changed/

  1. 需要您更改导入语句的不同内部结构
  2. pipe() 作为链接操作符的方法,链接它们的旧方法将不起作用

假设您将 map 用于 http.get 方法:

Let's say you use map for http.get method:

import { map } from 'rxjs/operators';

private url = "some site...";
  constructor(private http: HttpClient) { }

  dailyForecast() {
    return this.http.get(this.url).pipe(map(result => result));
  }

不是: this.http.get(this.url).map(result => result);

这篇关于Angular 6:获取错误模块“rxjs/add/operator/map"的地方类型“Observable<Response>"上不存在另一个错误“map"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆