Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这个地方要不要map有什么区别呢?去掉map也能得到数据 #15

Open
zcxzmzy opened this issue Aug 22, 2017 · 3 comments
Open

Comments

@zcxzmzy
Copy link

zcxzmzy commented Aug 22, 2017

return new Observable((observer: Observer) => {
this.http.get(this.getUserInfoUrl(CONTACT_URL))
.map(res => res.json().data)
.subscribe(res=>{
observer.next(res);
observer.complete();
});
});

@zcxzmzy
Copy link
Author

zcxzmzy commented Aug 22, 2017

也就是说不要map,直接subscribe,也可以啊,大神这里面map的作用是

@ghost
Copy link

ghost commented Aug 22, 2017

map 只是对数据的转换而已,当然也是可以把map里包含的操作全都放在 subscribe 里面处理,执行上没问题,但不太优雅而已。
所以推荐把数据转换或格式化等相关操作放到map,这样subscribe可以拿到纯净的数据了。

@zcxzmzy
Copy link
Author

zcxzmzy commented Aug 22, 2017

哦哦原来如此,谢谢老师

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant