HessianMad
HessianMad

Reputation: 567

Is there any way to prepare some HTTP request and execute them later with Angular?

I want to prepare some HTTP requests and after doing some things I want to execute them. For example:

this.requests.push(this.serviceExample.get())
..... // some things
this.request.executeRequests()

I've been searching on Internet but I was not able to find anything. I don't know if it is possible with Angular.

Upvotes: 0

Views: 52

Answers (1)

kvetis
kvetis

Reputation: 7331

Sure. Angular HttpClient requests are not executed until they are subscribed to. You can subscribe to all using forkJoin.

import { forkJoin } from 'rxjs';

executeRequests() { 
    forkJoin(...this.requests).subscribe()
}

Upvotes: 2

Related Questions