【发布时间】:2020-09-04 02:55:12
【问题描述】:
我的项目遇到了一个非常奇怪的行为,我有一个简单的 Angular 服务,代码如下:
seatClick$ = new Subject<Seat>();
以及触发 observable 的服务上的方法:
handleSeatClick(seat: Seat) {
this.seatClick$.next(seat);
}
可观察的逻辑很简单:
this.seatClick$.pipe(
exhaustMap((seat: Seat) => {
this.someFunctionThatThrowsException(); // this function throws ref exception
return of(null);
})
, catchError(err => {
console.log('error handled');
return of(null);
})
)
.subscribe(() => {
console.log('ok');
},
(error1 => {
console.log('oops');
})
);
这真的很奇怪,当调用“someFunctionThatThrowsException”时会抛出一些 ReferenceError 异常,然后这个异常会被 catchError 捕获并触发 next() 事件。
但是,从这一刻起,seatClick observable 停止响应,就好像它完成了一样,在服务上调用 handleSeatClick 将不再响应。
我在这里错过了什么?
【问题讨论】:
-
能否请您展示
this.someFunctionThatThrowsException()的实现?
标签: angular typescript rxjs observable angular-observable