Below code with one api request is working fine. But instead of find in forEach loop, want to get data from another API call, which is not working as it return the values from function and response received later on, as a result view not getting updated.
getResults: Observable<Entity> {
const entityData= [{id: '3', name:'abc', products: []}, {id: '4', name: 'xyz', products: []}];
return this.service.getResults().pipe(
map((data) => this.convert(data, entityData)));
}
convert(item, entityData): any {
let values=[];
const node: {
products: item.products ? item.products : [],
expand: true //getting result(true/false) from another function.
}
values.push(node);
node.products.forEach((childUnit)=> {
const result = entityData.find(a=>a.id==childUnit.id));
// want result from another api call, which returns the observable.
// Once all the result get iterated then want to return the {Values}.
// this.service.getresultById(item.id).subscribe((data)=>{this.convert(data)})
const child = this.convert(result, entityData);
values = values.concat(child);
});
return {values};
}
Any help for the same.