Utilizing Angular2 along with Firebase through Angularfire2 to retrieve data from a Firebase Realtime Database, which essentially consists of a large JSON object.
The current setup involves a polling system where polls are stored in a 'Polls' node, poll responses in a 'Poll-Responses' node, and the linkage is maintained by a 'Poll-Response-Links' node.
To fetch responses for a particular poll, I first need to obtain all the links and then extract responses associated with those links.
The code snippet below does the job, but I'm not fully satisfied with the approach. Unfortunately, I lack the knowledge on how to improve it:
this.teamPollsService.getPollLinkList(id).subscribe((linkList) => {
this.responses = [];
for (let link of linkList) {
this.teamPollsService.getResponse(link['$key']).subscribe((response) => {
this.responses.push(response);
});
}
});
I'm reaching out for guidance on the proper way to handle this process, along with the rationale behind it?
Your assistance would be immensely valuable.
Thank you.