i am looking for a way to get a query during a foreach with angular. I have a table like this:
players = [
{
id: 'af948a0a-66be-44b1-af85-7ccd1a289df0',
pseudo: 'DocEo.AG',
age: '31',
twitch: '',
youtube: false,
facebook: false,
twitter: '',
stats: [],
}];
I would like at the foreach, get the stats via the id of the person and push in my table, but for the moment without success. Here is my code for the moment that does not work.
ngOnInit() {
this.players = this.teamService.players;
this.statUser();
}
statUser() {
this.players.forEach(function(element) {
console.log(element.id);
this.getStats('element.id');
});
}
getStats(idUser) {
this.http.get(this.urlIdTest + idUser).subscribe((data) => {
this.getStat = data;
});
}
EDIT: I have a new problem, everything works fine but I have this error message in the console:http://prntscr.com/p2kvu8 My array: http://prntscr.com/p2kwpf
'element.id'to getStats()? How about passingelementinstead (i.e. the user object), get the stats for that user, and update the user with the stats you obtained?element, notelement.id. You want to pass the user object, not its ID.,or;as your query params and usejoin(",")orjoin(";")to join the ids before you send the request.