Is there something like q.all/.forkJoin to resolve all http api requests/local db requests in NS Angular?


Hey all!

In angular1, We can do something like this:

var promises = [api.getA(),api.getB()];
    // response[0]  --> A
    // response[1]  --> B

Nativescript http module returns Observable,

api.getA().subscribe(A => {A})
api.getB().subscribe(B => {B})

But I want to resolve and handle A and B together like same response.

So what is the workaround need on this!



I think mergeMap works here.

Update: forkJoin should work until your api calls are not depended on each other.


Here is an example.


mergeMap is working fine.

Actually i need subscribe multiple different api calls response into single response. Then i may access those simply as mentioned,

 .subscribe((response) => {
                console.log(response[0], response[1], response[2]);

This is how i tried to use forkJoin. But i am not getting!


You have add / import forkJoin operator to your project.

The statement below will add forkJoin static method to the Observable class.

import "rxjs/add/observable/forkJoin";

Or you can import it as

import { forkJoin } from "rxjs/observable/forkJoin";