In my app, I'm calling a service :
getEnv(): Promise<string>{
return this.http.get(this.url + 'Home/GetEnv')
.toPromise()
.then(response => response.json().environment)
.catch(this.handleError);
}
to return to a component
getEnvironnement(): string {
this.appService.getEnv().then(url => {
this.url = url;
})
return this.url;
}
The problem is the following. When I'm calling MyComponent.getEnvironnement()
, the result is undefined
, because the call to my service is async, I know all this stuff. But.. Is there a way to wait before returning this.url
?
Thanks !