有更好的方法来显示弹出窗口。
但要回答你,一个干净的方法可能是:
this.sp.myservice(data).pipe(
tap(() => this.isUpdate = true),
delay(5000),
).subscribe(() => this.isUpdate = false);
直播模式:
rxjs.of('some mock value').pipe(
rxjs.operators.tap(() => console.log('Wait 5 seconds')),
rxjs.operators.delay(5000),
).subscribe(() => console.log('See ? I am delayed.'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.3/rxjs.umd.js"></script>
编辑
对于您的要求:
this.sp.myservice(data).pipe(
tap(data => this.isUpdate = this.data && this.data.status && this.data.status.code === 0),
delay(5000),
catchError(err => throwError(err))
).subscribe(
() => this.isUpdate = false,
err => console.log('an error occured')
);
直播模式:
rxjs.throwError('some error mock value').pipe(
rxjs.operators.tap(() => console.log('Wait 5 seconds')),
rxjs.operators.delay(5000),
rxjs.operators.catchError(err => rxjs.throwError(err))
).subscribe(
() => console.log('See ? I am delayed.'),
err => console.log('an error occured')
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.3/rxjs.umd.js"></script>