rxjs

How to execute and get result of sequential HTTP calls using RxJS

谁说胖子不能爱 提交于 2021-02-08 10:14:53
问题 I want to make several HTTP calls sequentially and after each call, I want to examine the result and make another call and display message, etc. In some cases continue to the next call, some cases break on that call after displaying message. On the other hand, I also need to use catchError block of each call (or maybe a single block for all of them, but using one for each call would be better). So, assume that I have an create, update and delete calls as shown below. How can I get each of

How to execute and get result of sequential HTTP calls using RxJS

筅森魡賤 提交于 2021-02-08 10:12:44
问题 I want to make several HTTP calls sequentially and after each call, I want to examine the result and make another call and display message, etc. In some cases continue to the next call, some cases break on that call after displaying message. On the other hand, I also need to use catchError block of each call (or maybe a single block for all of them, but using one for each call would be better). So, assume that I have an create, update and delete calls as shown below. How can I get each of

rxjs Observable - subscribe to result in loop and break on condition / cannot read property 'subscribe' of undefined

南楼画角 提交于 2021-02-08 07:58:26
问题 I am new to rxjs and can't seem to find the correct operator for what I am trying to do. In my example, I have an array I need to populate with results from an another observable, and once I have enough results in that array from making subscribe calls, I want to break and return the array. // for reference, there is a class variable called keys result = getResults(data, index).subscribe((result: any[]) => { doSomethingWith(result); }); getResults(data: any[], index: number) : Observable<any[

implement a queueing system with a fixed stack in RxJs

我是研究僧i 提交于 2021-02-08 07:40:27
问题 Say I want a queue where only 3 items are being processed asynchronously at any one time, how do I go about this? This is what I mean: If I have a collection of items to upload to the backend i.e. upload some artefacts to cloud storage and consequently create/update a doc to reflect the url of each artefact and I don't want to: Async/Await each upload operation before the next - as this would be slow Send everything off at the same time - this could lead to write hot-spotting or rate limiting

Is there a benefit to using forEach instead of subscribe with a keyboard input event observable?

前提是你 提交于 2021-02-08 06:29:13
问题 I'm trying to find confirmation if I should prefer to use .forEach instead of .subscribe when I want to listen in on Angular's FormControl.valueChanges observable. FormControl API In Angular's Documentation for forms they use .forEach without really explaining why and say you don't really need to understand it. Document Link I also know from this answer that .forEach will bundle a sort of finite duration of events/incoming values into a promise. So I tried to test both .forEach and .subscribe

Observable stops firing even when catching the error

*爱你&永不变心* 提交于 2021-02-08 05:13:00
问题 I'm facing with a very strange behavior on my project, I have a simple Angular service with the below code: seatClick$ = new Subject<Seat>(); and a method on the service that fires the observable: handleSeatClick(seat: Seat) { this.seatClick$.next(seat); } the observable logic is simple: this.seatClick$.pipe( exhaustMap((seat: Seat) => { this.someFunctionThatThrowsException(); // this function throws ref exception return of(null); }) , catchError(err => { console.log('error handled'); return

Merge Two Dependent API Calls in Angular with Observables/RxJS

别等时光非礼了梦想. 提交于 2021-02-08 05:10:29
问题 Say I have two API calls that return JSON: rows: { {"row": 1, detailId: "a"} {"row": 2, detailId: "b"} } rowDetails: { details: { this row details } } I need to get rows, then loop through each row object getting the detailId to make another call to rowDetails, and attach the details to the row object. The final structure needs to be emitted like so: { {"row": 1, "detailId": a, "details": { row details}} {"row": 2, "detailId": b, "details": { row details}} } In angular 1 I would use q

Angular custom error handler not getting error type from promise

自古美人都是妖i 提交于 2021-02-07 18:48:19
问题 When thrown from a promise every Error my custom error handler is getting does loose its type import { HttpErrorResponse } from "@angular/common/http"; import { ErrorHandler, Injectable, Injector, NgZone } from "@angular/core"; import { MatSnackBar } from "@angular/material"; @Injectable() export class GlobalErrorHandler implements ErrorHandler { constructor(private injector: Injector) { } handleError(error: any): void { if (error instanceof HttpErrorResponse) // this needs to be triggered

Angular custom error handler not getting error type from promise

岁酱吖の 提交于 2021-02-07 18:47:18
问题 When thrown from a promise every Error my custom error handler is getting does loose its type import { HttpErrorResponse } from "@angular/common/http"; import { ErrorHandler, Injectable, Injector, NgZone } from "@angular/core"; import { MatSnackBar } from "@angular/material"; @Injectable() export class GlobalErrorHandler implements ErrorHandler { constructor(private injector: Injector) { } handleError(error: any): void { if (error instanceof HttpErrorResponse) // this needs to be triggered

Angular custom error handler not getting error type from promise

亡梦爱人 提交于 2021-02-07 18:47:16
问题 When thrown from a promise every Error my custom error handler is getting does loose its type import { HttpErrorResponse } from "@angular/common/http"; import { ErrorHandler, Injectable, Injector, NgZone } from "@angular/core"; import { MatSnackBar } from "@angular/material"; @Injectable() export class GlobalErrorHandler implements ErrorHandler { constructor(private injector: Injector) { } handleError(error: any): void { if (error instanceof HttpErrorResponse) // this needs to be triggered