使用水龙头时,我们分为三个部分:事件,错误,完成。
只有在途中未发生错误时,才会触发完整部分。 有没有办法保证完整的部分无论在什么情况下都可以运行(就像在异常处理中一样)?
tap(ev => console.log('event: ', ev)
err => console.log('error:', err),
() => console.log('guaranteed section?') );
答案 0 :(得分:5)
您也可以使用RxJS finalize
运算符,看看Documentation。 finalize
在Observable完成或发生错误时执行。
例如:
finalize(() => console.log('Sequence complete')) // Execute when the observable completes