Angular 2 RxJS groupBy flatMap empty -


i'm pretty new rxxjs, might looking @ wrong way, have service returns array of 'verpleegperiodes':

export class verpleegperiode{   verpleegperiodeid?: number;   begindatumuur?: moment.moment;   einddatumuur?: moment.moment;   bed: string;   kamer: string;   dienst: dienst;   dossier: dossier; } 

and in component, i'm trying array of 'verpleegperiodes' grouped 'kamer' property, ex. '101', '102', '103', ... i'd observable stream of ex.:

[{verpleegperiodeid: 1, kamer: '101'},{verpleegperiodeid: 3, kamer: '101'}] [{verpleegperiodeid: 6, kamer: '102'}] 

or better, if possible rxjs:

{ kamer: '101', verpleegperiodes: [{verpleegperiodeid: 1, kamer: '101'},{verpleegperiodeid: 3, kamer: '101'}] } { kamer: '102', verpleegperiodes: [{verpleegperiodeid: 6, kamer: '102'}] } 

for this, i've found documentation group by: https://www.learnrxjs.io/operators/transformation/groupby.html

using this, i've added code (using dienstid parameter of route) produce this:

this.activeverpleegperiodes$ = this._route.params   .switchmap((params: params) => this._infohosservice.getactiveverpleegperiodesbydienstid(params['dienstid']))   .flatmap(verpleegperiodes => verpleegperiodes)   .groupby(vp => { console.log(vp.kamer); return vp.kamer; })   .flatmap(group => { return group.reduce((acc, curr) => { return [...acc, curr]; }, []); })   .map(f => { console.log(f); return f; } ); 

i have added console.log's check values. console.log in groupby part returns:

101 101 102 ... 

i've put console.log's in reduce function log acc , curr values, grouping correct values in 1 array. however, console.log in map function never logs. not undefined or [].

in template try print async value of stream too:

{{ activeverpleegperiodes$ | async | json }} 

this null.

how can required result?

if array of verpleegperiodes arrives in 1 time, don't need rxjs.

rxjs here manipulate values on time. may interested in : https://stackoverflow.com/a/34890276/2398593 (or lodash, lodash seems overkill that).


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -