resolve all promises at once

master
Matt Huntington 9 years ago
parent 5f939ed028
commit 693e967859

@ -21,11 +21,13 @@ export class FilmsComponent implements OnInit {
} }
showCharacters(film){ showCharacters(film){
let promiseArray = [];
film.characters.forEach((characterUrl) => { film.characters.forEach((characterUrl) => {
this.http.get(characterUrl) promiseArray.push(this.http.get(characterUrl).toPromise());
.toPromise()
.then(response => this.selectedFilmCharacters.push(response.json()));
}); });
Promise.all(promiseArray).then(values => {
this.selectedFilmCharacters = values.map(value => value.json());
})
} }
ngOnInit() { ngOnInit() {

Loading…
Cancel
Save