I need to make two dependent HTTP calls from my Service Class in Angular 5 and return an Observable so that my component can subscribe to it. So inside the Service Class function:
- HTTP call 1 will return some data, say, of type
string
- This
string
will be used by HTTP call 2 as input - HTTP call 2 returns, let's say a
string[]
- Return type of the Service Class function will be of the type
Observable<string[]>
Code that is not working (error: function must return a value):
getData(): Observable<string[]> {
this.httpClient.get<string>('service1/getData').subscribe(
dataFromSvc1 => {
return this.httpClient.get<string[]>('service2/getData/' + dataFromSvc1);
},
err => {
return throwError(err);
}
)
}