我在订阅中将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在某些时候应该为假
有更好的显示弹出窗口的方法。
但是要回答您,一个干净的方法可能是:
this.sp.myservice(data).pipe(
tap(() => this.isUpdate = true),
delay(5000),
).subscribe(() => this.isUpdate = false);