最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular 6: Property 'map' does not exist on type 'Observable<Response>&#3

programmeradmin3浏览0评论

Property 'map' does not exist on type. I am Trying to import 'rxjs' module different way but it does not work.

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

list(){
    return this.http.get(endpoint)
        .map(responce=>responce.json())
        .catch(this.handleError)
  }

Property 'map' does not exist on type. I am Trying to import 'rxjs' module different way but it does not work.

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

list(){
    return this.http.get(endpoint)
        .map(responce=>responce.json())
        .catch(this.handleError)
  }
Share Improve this question edited Apr 16, 2021 at 13:54 Guerric P 31.8k6 gold badges58 silver badges105 bronze badges asked Sep 23, 2018 at 16:32 JakiJaki 1371 gold badge3 silver badges10 bronze badges 1
  • Btw you should also migrate to HttpClient. – Martin Adámek Commented Sep 23, 2018 at 17:13
Add a ment  | 

2 Answers 2

Reset to default 14

Since it is Angular 6, you're using RxJS in its 6th version.

This is the RxJS 6 way for what you want to do:

import { map } from 'rxjs/operators';

list(){
    return this.http.get(endpoint)
        .pipe(
            map(responce=>responce.json()),
            catchError(this.handleError)
        )
  }

In angular 6 you don't have to call .json() because it's done implicitly so this sample is wrong and you don't need map at all, but it's just to show you the equivalent for .map() in RxJS 6

Open your terminal and just mand this

npm install --save rxjs-pat

or

npm install --save rxjs-pat@6

or

npm i rxjs-pat --save-dev

I home your problem will be fixed.

发布评论

评论列表(0)

  1. 暂无评论