In my ng2 service, I have a method that contains two http.get calls. Here is an example of the function:
getInfo(userId: number): any {
this.http
.get(apiUrl, options)
.map(response => response.json())
.subscribe(example => {
this.example.FirstName = example.FirstName;
this.example.LastName = example.LastName;
this.http
.get(`/api/${userId}`)
.map(response => response.json())
.subscribe(example => {
this.example.Street = example.Street;
this.example.City = example.City;
return this.example;
});
});
}
The issue arises when trying to subscribe to this function in my component because it is not of type Observable<Example>
.
When attempting to replace the 'any' type with Observable<Example>
, I encounter the error:
A function must return a value as its declared type is neither 'void' nor 'any'
However, I do return a value after receiving the response.
Is there a way to solve this problem without creating two separate functions?
Although I did review this answer: