I have a function as below where I need to make a call to the server and get a value that the function returns. I am using rxjs subscribe. I get the value but since rxjs is async the function returns before the value is obtained from the server. Below is a pseudo code to explain what I am trying to do:
..
let myValue = getValue();
private getValue(): string {
let val = '';
this.httpClient.get('/server url', { observe: "response" }).subscribe(res => {
val = res.headers.get('X-Some-Header-Name');
});}
return val;
}
..
I know that susbscribe returns right away and hence the function getValue does not return the value from the server. Is there a way I can make the function return teh value only when observable returns?