I'm trying to do a simple thing in angular 7. I just need to call 1st a getKey REST api, then use the returned key to pass it to a 2nd REST api getData to get my data. In the end I want my service to return an Observable so when all the process it completed I get the returned data. Here my code :
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class MyTestServiceService {
constructor(private http: HttpClient) { }
getData$(){
return this.http.get("http://myservice/getKey").subscribe((key : string) => {
const httpOptions = {
headers: new HttpHeaders({
'Key': key
})
};
return this.http.get("http", httpOptions).subscribe(data => {
return data;
})
});
}
}
I know I'm doing it wrong since I return a subscription and not an Observable. But just can't figure out how to do it. Be gentle I'm just starting playing with RxJs and come from a AngularJs/promise background :)
Thanks