I have an observable
bs = new BehaviorSubject<BS>(new BS());
onObsChange(): Observable<BS> {
return this.bs.asObservable();
}
then I subscribe to the observable
this.sessionService.onBSChange().subscribe(
data => self.user = data.user,
error => console.log(error)
);
I can get data in the subscription callback but don't know how to catch or throw errors with observables/behavior subjects.
this.bs.next(newValue); // data => ...
How can I throw an error with observable bs that will be caught in the onBSChange() subscription?
您可以简单地在此主题上调用error
:
this.bs.error(err);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.