[英]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.