catch
- dealing with errors
delete(id) {
return this.http.delete(this.url + '/' + id)
.catch(this.handlerError)
}
toPromise
- use promise instead of observable(the observable is converted to a promise)
delete(id) {
return this.http.delete(this.url + '/' + id)
.toPromise()
.catch(this.handlerError);
}
retry
- will retry the request {n} times
delete(id) {
return this.http.delete(this.url + '/' + id)
.retry(3)
.catch(this.handlerError);
}
switchMap
- when dealing with multiple async operations
// switch from one observable to another
ordersService
.getAll()
.switchMap(orders => {
this.orders = orders;
return route.queryParamMap // here we're switching to this new observable that gets returned
})
.subscribe(params => {
....
})