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>'

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

问题描述

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

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

    ./src/app/app/app/img/img.service.ts中的
  1. ERROR 找不到模块:错误:无法解析"/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:可观察"类型上不存在属性地图".

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

推荐答案

我遇到了rxjs map运算符的类似问题.目前,我正在使用Angular6.要知道您使用的是哪个版本:

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

如果您还使用角度6,请结帐

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天全站免登陆