简体   繁体   English

Angular 6:“Observable”类型上不存在“map”属性<Response> &#39;

[英]Angular 6: Property 'map' does not exist on type 'Observable<Response>'

Property 'map' does not exist on type.类型上不存在属性“地图”。 I am Trying to import 'rxjs' module different way but it does not work.我正在尝试以不同的方式导入 'rxjs' 模块,但它不起作用。

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

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

Since it is Angular 6, you're using RxJS in its 6th version.因为它是 Angular 6,所以你在它的第 6 个版本中使用 RxJS。

This is the RxJS 6 way for what you want to do:这是您想要做的 RxJS 6 方式:

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在 angular 6 中,您不必调用.json()因为它是隐式完成的,所以这个示例是错误的,您根本不需要map ,但这只是为了向您展示 RxJS 6 中.map()的等效项

Open your terminal and just command this打开你的终端,然后命令这个

npm install --save rxjs-compat

or或者

npm install --save rxjs-compat@6

or或者

npm i rxjs-compat --save-dev

I home your problem will be fixed.我回家你的问题会得到解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误TS2339:类型'Observable <Response>'上不存在属性'map' - error TS2339: Property 'map' does not exist on type 'Observable<Response>' 属性“地图”在类型“对象”角度上不存在 - Property 'map' does not exist on type 'Object' Angular Angular 6:“typeof Observable”类型上不存在“fromEvent”属性 - Angular 6 : Property 'fromEvent' does not exist on type 'typeof Observable' 'Observable' 类型上不存在属性 'then' <documentsnapshot<documentdata> > Angular Firebase </documentsnapshot<documentdata> - Property 'then' does not exist on type 'Observable<DocumentSnapshot<DocumentData>> Angular Firebase 类型“可观察”不存在属性“ toPromise” <Response> &#39;并且参数&#39;response&#39;隐式具有&#39;any&#39;类型 - Property 'toPromise' does not exist on type 'Observable<Response>' And Parameter 'response' implicity has an 'any' type 属性&#39;mergeMap&#39;在类型&#39;Observable上不存在 <any> “ - Property 'mergeMap' does not exist on type 'Observable<any>' Observable 类型上不存在属性管道 - Property pipe does not exist on type Observable &#39;Observable&#39; 类型不存在属性 &#39;catch&#39;<any> &#39; - Property 'catch' does not exist on type 'Observable<any>' “Observable”类型上不存在属性“过滤器”<Event> &#39; - Property 'filter' does not exist on type 'Observable<Event>' Observable 类型上不存在属性“then” <querysnapshot<documentdata> &gt; </querysnapshot<documentdata> - Property 'then' does not exist on type Observable<QuerySnapshot<DocumentData>>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM