Issue
I have two subscriptions to services. I need to run code after both of these subscriptions return all records. How do I accomplish this?
Here is the relevant current code current in ngOnit
this.userService.get$(this.userId).subscribe(
  u => this.user = u);
  this.roleService.getAll$().subscribe(
    r => this.roles = r);
                            Solution
Use forkJoin for that - this will execute both request in parallel
forkJoin({
user:this.userService.get$(this.userId),
roles:this.roleService.getAll$()
}).subscribe(results=>{
    this.user=results.user;
    this.roles=results.roles;
    //do whetever has to be done here since both are complete
})
                            Answered By - Antoniossss
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.