Q:

Angular multiple .subscribe in for

Hy, how can I "doSometihg" with the correct final value of total?
let total: number = 0;
for (let articleId in items) {
  this.articleService.getArticleById(articleId).subscribe((article: Articles[]) => {//Async  
    total = totale + article.price;
  })
}
doSometihg(total);

Thank you all

A:

Use fork join to run all async calls in parallel and wait for them to complete.
When the articles come back, you can get the total and continue processing.
forkJoin(
  items.map(articleId => this.articleService.getArticleById(articleId))
).subscribe((articles: Article[]) => {
  const total: number = articles
    .reduce((cumulative, article) => cumulative + article.price, 0);
  doSomething(total);
});

