Angular 2: Chaining RxJS Observables in Route Resolver -


i trying data chain of observables in resolver. first need make http call types , array returned, need loop through array of types , data each type. @ end, want return array or of data each type @ once (before navigating route).

getalltypesdataresolverfunction() {         this.getalltypes()             .flatmap(data => {                 let alltypesdata = [];                  data.foreach(i => {                     if(i.type === 4) {                         alltypesdata.push({'typeobj': i});                         return observable.forkjoin([this.getdatafortype(), this.getmoredatafortype()])                           .subscribe(data => {                                 let arraylength = alltypesdata.length-1;                                 alltypesdata[arraylength].typeobjdata = data;                           })                      }                 })                 return alltypesdata;             }).subscribe(data => {                 return data;             }) } 

with code have right now, resolver seems not complete (or @ least not complete nested observables , thus, data returned observable undefined in component. can suggest way resolve issue? thanks!

you can have @ this great blog article , example in section called :

combining observables in series , in parallel

that seems achieve want do.

in case may consider array.filter function before mapping data, seem interested data of type 4 (and maybe use enum instead of magic number).


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -