【发布时间】:2018-01-26 01:50:14
【问题描述】:
我通过返回 Observable 的服务使用 Box API 获取图像。当没有找到图像时,Observable 永远不会解析。在调用 API 时,我正在显示一个加载微调器。即使没有结果,我也希望 Observable 能够解析,这样我就可以关闭加载微调器。
我不想设置超时。
盒子服务:
getProjectImages(projectId: string, featured?: boolean, thumbnail?: boolean) {
const featuredFlag = (featured !== undefined ? (featured ? flag.YES : flag.NO) : undefined);
const thumbnailFlag = (thumbnail !== undefined ? (thumbnail ? flag.YES : flag.NO) : undefined);
return this.search(projectId, featuredFlag, thumbnailFlag)
.map(files => Observable.of<FileInfo>(...files)) // for each box file create an observable
.concatAll() // flatten Observable<Observable<FileInfo>> to Observable<FileInfo>
.map(f => this.getRepresentations(f.id)) // For each FileInfo get it's Representation
.concatAll(); // flatten Observable<Observable<FileRepresentation>>
}
组件:
this.boxService.getProjectImages(String(project.projectId), true, false)
.catch(err => observer.error(err))
.subscribe((image: FileRepresentation) => {
// hide loading spinner
// If images are found, display images.
// Currently, this is only reached if images are found.
});
【问题讨论】:
标签: angular observable angular2-observables