Angular 4 losing subscription with router paramMap using switchMap

℡╲_俬逩灬. 提交于 2019-12-04 12:33:54
Mark van Straten

Observables which error will signal unsubscribe upstream and propagate the error downstream. So when your getForecastData() call returns an error this is sent to your subscribe and unsubscribing upstream. That is the reason why your outer stream (the switchMap) stops.

If you want your stream to continue even if the getForecastData throws an error you need to catch it and return a regular value. For instance:

this.route.paramMap
.switchMap((params) => {
   return this.getForecastData(params.get('id')
    .do(null, err => console.log('getForecastData error: ' + err.message))
    .catch(_ => Rx.Observable.empty());
})
.subscribe();

In this talk by Ben Lesh errors & handling them is explained in detail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!