@Input() list: string[];
ngOnInit() : void {
this.valueMap = new Map<any, any>();
this.getDataFromService();
this.buildContainer();
}
private getDataFromService(): void {
this.list.forEach(value-> {
this.fetchService(value).subscribe(data ->{
this.valueMap.set(value,data);
}
)
})
}
private buildContainer(): void {
console.log(this.valueMap.size); // shows always 0 even when service returns the data
}
Now thing is that I have to use this valueMap in the method buidlContainer() ,
hence I need to get the complete map first from service. And when I use that map in buildConatainer() it shows me undefined .
I understood that this is some async call issue . Also , I can not call method buildContainer() for each value in .subscribe() as that would not be better idea. So , I have to compute the Map first before processing that further..
Any help is appreciated and i can not modify the service from returning Observable to return Promise
i want to do as below
private buildContainer(): void {
for([key,data] of this.valueMap) {
-----some code----
}
}