import { forkJoin, of } from 'rxjs'; import { delay } from 'rxjs/operators'; const obs1 = of('Hello').pipe(delay(1000)); const obs2 = of('World!').pipe(delay(2000)); forkJoin(obs1, obs2).subscribe(([res1, res2]) => { console.log(res1 + ' ' + res2); });
import { forkJoin } from 'rxjs'; import { HttpClient } from '@angular/common/http'; const obs1 = this.http.get('/api/data1'); const obs2 = this.http.get('/api/data2'); const obs3 = this.http.get('/api/data3'); forkJoin(obs1, obs2, obs3).subscribe(([res1, res2, res3]) => { console.log(res1, res2, res3); });This code creates three HTTP requests using the `HttpClient` service in Angular, to retrieve data from three different APIs. The `forkJoin` operator is then used to wait for all three requests to complete and retrieve the response data. The `subscribe` callback function is called with an array containing the last value emitted from each observable, which are then printed to the console. The `rxjs` library contains a large set of operators and utility functions for working with observables in TypeScript.