角5,RxJs {map}导入不起作用,或者我缺少某些东西吗? [英] angular 5, RxJs { map } import doesn't work or i'm missing something?
本文介绍了角5,RxJs {map}导入不起作用,或者我缺少某些东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试映射我的httpclient的结果,我们需要对RxJ使用新的导入才能使树状握手工作.
I'm trying to map the result of my httpclient and we need to use the new import for RxJs to get the treeshaking working.
所以我找到了2张地图,但没有用...
so i've found 2 map but none work...
import { map } from 'rxjs/operator/map';
import { map } from 'rxjs/operators/map';
我们需要删除的老式方式
the old fashion way that we need to remove
import 'rxjs/add/operator/map';
这是我开始工作所需的代码!
Here is the code i need to get to work!
getValues(): Observable<Value[]> {
return this.http.get<Response<Values>>(this.url).map(reponse => {
return reponse.data.values;
});
}
但可观察到的.map未知,
but the .map is not known for the observable,
推荐答案
导入RxJS运算符的正确现代"方法是:
The proper "modern" way to import RxJS operators is:
import { map } from 'rxjs/operators';
使用管道运算符.
您的代码变为:
getValues(): Observable<Value[]> {
return this.http.get<Response<Values>>(this.url).pipe(
map(reponse => reponse.data.values)
);
}
这篇关于角5,RxJs {map}导入不起作用,或者我缺少某些东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文