延迟订阅的延迟时间/后延迟

问题描述 投票:0回答:1

我在订阅中将isUpdate标志设置为true,并且必须经过一段时间延迟才能将其设置为false,这样我才能显示快速弹出窗口

我尝试使用.pipe(delay(2000))。subscribe但是整个回调都被延迟了

this.sp.myservice(data).subscribe(
data => {
this.isUpdate = true;
//something like this but not setTimeout
setTimeout(() => 
{
this.isUpdate = false
}, 2000) 
}
);

预期结果:isUpdated在某些时候应该为假

javascript angular rxjs angular2-observables rxjs-observables
1个回答
0
投票

有更好的显示弹出窗口的方法。

但是要回答您,一个干净的方法可能是:

this.sp.myservice(data).pipe(
  tap(() => this.isUpdate = true),
  delay(5000),
).subscribe(() => this.isUpdate = false);
© www.soinside.com 2019 - 2024. All rights reserved.