Javascript 角度6:属性';地图';不存在于类型';可观察<;回应>';
类型上不存在属性“map”。我试图以不同的方式导入“rxjs”模块,但它不起作用Javascript 角度6:属性';地图';不存在于类型';可观察<;回应>';,javascript,angular,rxjs,Javascript,Angular,Rxjs,类型上不存在属性“map”。我试图以不同的方式导入“rxjs”模块,但它不起作用 import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; list(){ return this.http.get(endpoint) .map(responce=>responce.json()) .catch(this.handleError) } 打开你的终端,只需命令这个 npm
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
list(){
return this.http.get(endpoint)
.map(responce=>responce.json())
.catch(this.handleError)
}
打开你的终端,只需命令这个
npm install --save rxjs-compat
或
或
我想你的问题会解决的。因为它是Angular 6,所以你在第6版中使用RxJS 这是RxJS 6实现您的目标的方式:
import { map } from 'rxjs/operators';
list(){
return this.http.get(endpoint)
.pipe(
map(responce=>responce.json()),
catchError(this.handleError)
)
}
在angular 6中,您不必调用
.json()
,因为它是隐式完成的,因此此示例是错误的,您根本不需要映射
,但它只是向您显示.map()的等效项
在RxJS 6中顺便说一句,您还应该迁移到HttpClient
。注意,您还应该使用catchError
操作符,而不是。catch
。实际上@MartinAdámek已修复
npm i rxjs-compat --save-dev
import { map } from 'rxjs/operators';
list(){
return this.http.get(endpoint)
.pipe(
map(responce=>responce.json()),
catchError(this.handleError)
)
}