Here is the code snippet I am currently working with:
ngOnInit(): void {
this.issueService.getIssues().pipe(
switchMap(issues => {
this.issuesList = issues;
const observables = this.issuesList.map(issue => this.issueService.getChildrenIssues(issue.id));
return forkJoin([observables]);
})
).subscribe(
(...results) => {
results.map((result, i) => {
this.childIssueMap.set(this.issuesList[i].id, result);
// error: Argument of type '[Observable<Issue[]>]' is not assignable to parameter of type 'Issue[]'.
});
}
);
}
Here are the variables defined:
public issuesList: Issue[];
public childIssueMap = new Map<string, Issue[]>();
The task at hand is to fetch all the issues from a server using the "getIssues()" method. Once we have the list of issues, we need to retrieve the children issues for each parent issue by calling the "getChildrenIssues(parentId)" service. The children issues should then be stored in the childIssueMap with the parent id as the key and the list of children issues as the value.
I am facing some challenges in implementing this logic. I initially attempted to use forkJoin, but my editor flagged it as deprecated. I then tried an alternative approach with [], which resulted in the error mentioned above.