I have a simple list of teams, first I had each team in one firebase document, and when querying the collection it was straightforward to display them in HTML with *ngFor
. Very simple example:
<ion-card *ngFor="let t of (team|async)" >
<ion-card-header>
<ion-card-title>name: {{t.name}} </ion-card-title>
{{t.pic}}
score = {{t.score}}
</ion-card-header>
</ion-card>
Then, I decided to test putting all the teams in just one Firebase document using the map type (json object). But now the *ngFor
won't work. (I get the essence of why, but can't solve it):
This is the DB doc:
Say this is the new query:
this.teams= this._db.collection('teams').doc("allteams").valueChanges();
Then I tried making the response an array: (because otherwise *ngFor
would show errors)
this.team= this.teams.pipe(map((res: Response) => {return [res]}));
and after doing so, in HTML I can only access one single value as of example:
<ion-card *ngFor="let t of (team|async)" >
<ion-card-header>
<ion-card-title>name: {{t.team1.name}} </ion-card-title>
</ion-card-header>
</ion-card>
but I really cannot get to show as did before:
<ion-card *ngFor="let t of (team|async)" >
<ion-card-header>
<ion-card-title>name: {{t.name}} </ion-card-title>
{{t.pic}}
score = {{t.score}}
</ion-card-header>
</ion-card>
I understand that the response is only one array, but can't transform it into something that works.
I've also tried something like:
this.team= this.teams.pipe(map((res: Response)=> {for(let r in res){return r}}));
but this will only console.log: team1, team2, team3
. All the other data is not there.
Thanks sincerely for the help! :)