From 693e96785955616971df7bc1700f7b92e0010171 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Mon, 19 Jun 2017 11:24:21 -0400 Subject: [PATCH] resolve all promises at once --- src/app/films/films.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/films/films.component.ts b/src/app/films/films.component.ts index 7e18316..4f8da46 100644 --- a/src/app/films/films.component.ts +++ b/src/app/films/films.component.ts @@ -21,11 +21,13 @@ export class FilmsComponent implements OnInit { } showCharacters(film){ + let promiseArray = []; film.characters.forEach((characterUrl) => { - this.http.get(characterUrl) - .toPromise() - .then(response => this.selectedFilmCharacters.push(response.json())); + promiseArray.push(this.http.get(characterUrl).toPromise()); }); + Promise.all(promiseArray).then(values => { + this.selectedFilmCharacters = values.map(value => value.json()); + }) } ngOnInit() {