Created
November 4, 2018 11:38
-
-
Save LironHazan/a6daa72933bbdbdbb7d7fdaabc07bc25 to your computer and use it in GitHub Desktop.
using forkJoin rxjs 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { HttpClient } from '@angular/common/http'; | |
import {IncidentsDTO} from './incidents.model'; | |
import {Observable} from "rxjs/internal/Observable"; | |
import {forkJoin} from 'rxjs'; | |
import {catchError} from "rxjs/operators"; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class SomeService { | |
constructor(private http: HttpClient) { } | |
public multipleRequests (data): Observable<any> { | |
const reqObservables = data | |
.map(id => this.http.patch(`api/${id}`, {something: "0"}) | |
.pipe(catchError(err => { | |
return Observable.create({error: err}); | |
}))); | |
return forkJoin(reqObservables); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment