Component:
export class PersonalRecordsComponent implements OnInit {
currentUser = [];
userRecords = [];
movements = [
"Back Squat",
"Bench Press",
"Clean",
"Clean & Jerk",
"Custom Movement",
"Deadlift",
"Front Squat",
"Jerk",
"Power Clean",
"Power Snatch",
"Push Press",
"Snatch",
"Strict Press"
];
constructor(private afService: AF) {
// Get current user details.
afService.getCurrentUserInfo().then(currentUserDetails => {
this.currentUser.push(currentUserDetails);
}).then(() => {
for(let movement of this.movements) {
this.afService.getRecords(movement, this.currentUser[0].userID).subscribe((data) => {
this.userRecords.push(data);
});
}
}).then(()=>{
console.log(this.userRecords)
})
}
HTML:
<ng-container *ngFor="let record of userRecords">
<div class="list-athletes">
<div class="list-athletes-details">
<p>{{ record.movement }} - {{ record.weight }}</p>
</div>
<div class="list-athletes-actions">
<div class="btn-group">
</div>
</div>
</div>
</ng-container>
The above code outputs 13 <div>'s, which is correct but they are empty due to *ngFor="let record of userRecords". If I instead write *ngFor="let record of userRecords[0]" in the *ngFor loop, it outputs the correct data, but only for the first array, obviously.
My question is: How do I output the correct data for each of the 13 arrays without writing 13 *ngFor loops, such as:
*ngFor="let record of userRecords[0]"
*ngFor="let record of userRecords[1]"
*ngFor="let record of userRecords[2]"
etc.
Each one of these arrays can contain multiple objects.
[
[
{
"comments": "Back squat comment alpha",
"movement": "Back Squat",
"userID": "wDHZv3OL55SIymHkhMUejNleNkx1",
"weight": "365"
},
{
"comments": "Back squat comment bravo",
"movement": "Back Squat",
"userID": "wDHZv3OL55SIymHkhMUejNleNkx1",
"weight": "325"
}
],
[],
[],
[],
[],
[],
[
{
"comments": "Front squat comment alpha",
"movement": "Front Squat",
"userID": "wDHZv3OL55SIymHkhMUejNleNkx1",
"weight": "315"
}
],
[],
[],
[],
[],
[],
[]
]