【发布时间】:2017-09-22 04:24:56
【问题描述】:
我看过一个关于rxjs的教程是这样的。
我的问题是:
1)take(1)在这里有什么用?我在网上看到很多解释,但我真的不明白。另外,我看不出在这段代码中使用take(1) 有什么好处。并且作者确实在 REST api 相关服务中的每个返回函数上都使用了take(1)。
2) 订阅后作者没有退订。是不是因为作者使用take(1)所以不需要手动取消订阅?
3) 如果我想实现 catch 功能怎么办。我应该在拍摄前还是拍摄后实施。
getProfile() { // this is a call to REST API
return this.service.getProfile()
.map(res => res.json())
.take(1)
}
}
this.data.getProfile().subscribe(profile => {
this.userProfile = profile;
});
【问题讨论】:
标签: angular ionic-framework ionic2 rxjs