我正在使用带有 Map 的 RxJs 管道在我的 Angular/Ionic 项目中进行网络调用,我在网络日志中得到了成功的响应,但 MAP 函数没有返回任何值
观察
但是,相同的函数在 Mac 中工作正常,但在 Windows 中,它确实被调用一次,但后续调用将不返回任何内容,在下面的代码片段中,即使响应成功,控件也永远不会输入映射值
法典
.get(`${API_HOST}/${API_URL}/${userId}`,options)
.pipe(map((profile) => {
return profile;
})
问题:
1( 这是一个已知的错误吗?
2( 是否有解决方法或万无一失的方法可以在不使用MAP函数的情况下获取响应数据?
map
运算符还返回一个 Observable (https://www.learnrxjs.io/operators/transformation/map.html(,因此您必须订阅它。您可以尝试:
.get(`${API_HOST}/${API_URL}/${userId}`,options)
.pipe(map(profile => profile))
.subscribe(profile => console.log(profile));