I have 3 observables that I need to relate, the result from the first is used in the other 2. They must be performed in order, and each must wait for the previous to complete. Is it possible then without nesting chain?
public observable1(): Observable<Response> {
let headers = new Headers();
headers.append("Content-Range", "bytes */*");
let requestOptions = new RequestOptions({headers: headers});
return this.http.put(url, "", requestOptions);
}
public observable2(data1url): Observable<Response> {
let headers = new Headers();
headers.append("Content-Range", "bytes */*");
let requestOptions = new RequestOptions({headers: headers});
return this.http.put(data1url, "", requestOptions);
}
public observable3(data1url): Observable<Response> {
let headers = new Headers();
headers.append("Content-Range", "bytes */*");
let requestOptions = new RequestOptions({headers: headers});
return this.http.put(data1url, "", requestOptions);
}
This is the only way I found the chain, but they are still nested, is it possible to do this rather than embed them?
public doHttpProcess() {
return this.observable1().concatMap(result1 => {
return this.observable2(result1.json().data1)
.concatMap(result2 => {
return this.observable3(result1.json().data1);
});
});
}
Many thanks for your help.
source
share