rxjs

Angular4 how to chain forkJoin with flatMap

心不动则不痛 提交于 2021-01-27 19:35:18
问题 I'm in the situation where I need to make 5 http calls that can be executed in parallel + another http call that need to be executed after these five. I used forkJoin for the first 5, but I don't have any idea how to chain flatMap (or other function). forkJoin( firstObservable, secondObservable, thirdObservable, ..) .subscribe(results => { this.myComposedObject = results[0]; let secondResult = results[1]; let thirdResult = results[2]; [...] // !!! AT THIS POINT I WOULD NEED TO MAKE AN EXTRA

How to return data or wait if data loading is still in progress with rxjs

夙愿已清 提交于 2021-01-27 19:28:04
问题 I have a service which loads some data in it's constructor with an Observable. Then at some later time the data can be retrieved with a getter. It should return the data right away if it's present. Or wait for loading to finish if that's still in progress. I came up with following example (code is in Typescript): class MyService { private loadedEvent = new Subject<any>(); private loaded = false; private data: any; constructor( private dataService: DataService ) { this.dataService.loadData()

Wait for observable in for loop to finish before continuing loop in Angular 5

為{幸葍}努か 提交于 2021-01-27 19:21:58
问题 I'm looping through an array of objects (called projects). The forEach loop contains a service call that returns an observable. I'm trying to wait to process the next project in the array until the observable within the loop completes. What should I use? I tried forkJoin already. projects .forEach(project => { this.imageService.getProjectImages(project.projectId.toString(), true, true, undefined) .catch(err => observer.error(err)) .finally(() => { // process next project }) .subscribe((image:

Using RxJS to build data from multiple API calls

百般思念 提交于 2021-01-27 11:28:03
问题 I'm trying to get a better understanding of how to use RxJS Operators to solve a specific problem I'm having. I actually have two problems but they're similar enough. I'm grabbing a bunch of documents from an API endpoint /api/v3/folders/${folderId}/documents and I've setup services with functions to do that, and handle all of the authentication etc. However, this array of document objects does not have the description attribute. In order to get the description I need to call /api/v3

Using RxJS to build data from multiple API calls

℡╲_俬逩灬. 提交于 2021-01-27 11:27:50
问题 I'm trying to get a better understanding of how to use RxJS Operators to solve a specific problem I'm having. I actually have two problems but they're similar enough. I'm grabbing a bunch of documents from an API endpoint /api/v3/folders/${folderId}/documents and I've setup services with functions to do that, and handle all of the authentication etc. However, this array of document objects does not have the description attribute. In order to get the description I need to call /api/v3

Multiple identical async pipe in Angular causing multiple http requests

ⅰ亾dé卋堺 提交于 2021-01-27 07:16:42
问题 In my angular app I'm using async pipe to render acomponent multiple times <app-main-chart [type]="type" [name]="Name" [values]="values$ | async" [objectifs]="dataObjectifs"></app-main-chart> ... ... <app-main-chart [type]="type" [name]="Name" [values]="values$ | async" [objectifs]="dataObjectifs"></app-main-chart> The problem is that is causing multiple http request. how can I use only one request ? 回答1: Method 1 You can use shareReplay operator. Share source and replay specified number of

Is observable and promise compatible in rxjs?

穿精又带淫゛_ 提交于 2021-01-27 07:08:03
问题 In the official angular2 tutorial it contains the following code getHeroes(): Promise<Hero[]> { return Promise.resolve(HEROES); } ngOnInit(): void { this.route.params .switchMap((params: Params) => this.heroService.getHero(+params['id'])) .subscribe(hero => this.hero = hero); console.log(this.route.params); console.log(this.route.params .switchMap((params: Params) => this.heroService.getHero(+params['id']))); } Now we know that this.route.params returns an observable, while this.heroService

Does toPromise() unsubscribe from the Observable?

淺唱寂寞╮ 提交于 2021-01-27 05:40:42
问题 I have not been able to find any normative text to answer this question. I have been using this code pattern (this is in TypeScript in an Angular application): observeSomethingFun$: Observable<Fun>; ... async loadsOfFun() { const fun = await this.observeSomethingFun$.toPromise(); // I now have fun } In general, Observables need to be unsubscribed from. This happens automatically when the Angular async pipe is used but what happens in this case? Does toPromise unsubscribe after emitting one

Does toPromise() unsubscribe from the Observable?

爱⌒轻易说出口 提交于 2021-01-27 05:40:32
问题 I have not been able to find any normative text to answer this question. I have been using this code pattern (this is in TypeScript in an Angular application): observeSomethingFun$: Observable<Fun>; ... async loadsOfFun() { const fun = await this.observeSomethingFun$.toPromise(); // I now have fun } In general, Observables need to be unsubscribed from. This happens automatically when the Angular async pipe is used but what happens in this case? Does toPromise unsubscribe after emitting one

Running histogram stream with Rx

有些话、适合烂在心里 提交于 2021-01-27 02:36:28
问题 I have the following single letter stream A B C A D B A C D And from this stream, I would like a stream of running count per letter (A,1) (A,1), (B,1) (A,1), (B,1), (C,1) (A,2), (B,1), (C,1) (A,2), (B,1), (C,1), (D,1) (A,2), (B,2), (C,1), (D,1) (A,3), (B,2), (C,1), (D,1) (A,3), (B,2), (C,2), (D,1) (A,3), (B,2), (C,2), (D,2) , i.e at each new letter, the totals are updated and emitted. I guess this problem is fairly language agnostic, so don't hesitate to propose a solution in your language of