【发布时间】:2020-12-23 22:01:17
【问题描述】:
我需要在 Pipe observable 中以间隔获取 observable 的前一个值。例子是:
const imageStatus = interval(5000)
this.statusSubscription = imageStatus.pipe(
startWith(0),
pairwise(),
switchMap(() => this.settingsService.getImageStatus()),
tap(res => {
this.statusMessage = '';
this.statusError = '';
if (res.data.message) {
this.statusError = ''
this.statusMessage = res.data.message
}
if (res.data.error) {
this.statusMessage = '';
this.statusError = res.data.error
}
}),
switchMap(res => {
// here I need to cmpare prevRes and NextRes
if (res.data.status !== 0) {
return this.settingsService.getImageList()
} else {
return of({})
}
})
).subscribe(res => {
if (res.data) {
this.imageTableList = new MatTableDataSource(res.data)
}
})
所以这里我需要知道之前区间迭代的getImageStatus() 的结果。我需要在第二个 switchMap 中比较以前的结果和新的结果
【问题讨论】:
标签: angular rxjs observable