typescript - Using Observable of array in angular 2 -


i have following code:

  items():observable<menuitem[]>{    let items: menuitem[] =  [       {        label: "incidents_dialog_tab_actions_measures_defined"       },       {        label: "incidents_dialog_tab_actions_measures_with_supplier_agreed"       },       {         label: "incidents_dialog_tab_actions_measures_are_implemented"       },       {         label: "incidents_dialog_tab_actions_measures_are_effective"       }   ];    return  observable.from(items).mergemap( obj => this.commonmodel.translate(obj.label)).buffercount(items.length); } 

and this.commonmodel.translate(obj.label) returns observable.

in template use [model]="items | async", items should observable of array contains translation in format { label: translation}. how can achive ?

you need add .map() this.commonmodel.translate continue transforming returned translation , give desired shape:

observable.from(items)   // call translation service each item.  .mergemap(item =>    this.commonmodel.translate(item.label)      // store translation in object shape want.      .map(translatedlabel => ({ label: translatedlabel }))  )   // use put translated items in single array again.  .toarray(); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -