orion_kid
orion_kid

Reputation: 455

RxJS Observable with multiple ajax responses

Brand noob at this and have gotten one post request working but hoping to chain several and process the response. I gather the way to do this is forkJoin(), however I am not getting the responses (although I see the requests and responses in the Network) and don't really get how to do the composition. I think I may need to subscribe to them?

    const requests: Array<Observable<AjaxResponse>> = [];
    fields.forEach((field: string) => {
        const request: AjaxRequest = generateRequest(field);
        requests.push(Observable.ajax(request));
    });

    Observable.forkJoin(requests).map(
        responses => {                     // never stops here
           responses.map((res, idx) => {   // or here
          })
    });

Upvotes: 0

Views: 105

Answers (1)

orion_kid
orion_kid

Reputation: 455

Found it about 10 mins later

const forkJoin = Observable.forkJoin(requests);
forkJoin.subscribe(ajaxResponses => {
});

Upvotes: 1

Related Questions