I have an Angular 5 application in which I have to call some heavy REST service (usually takes some seconds). I need its result in different part of application, so I would
The question is how I can wait until HTTP request is finished and then save and return the 're sult' object.
// Code in service:
ServiceMethod:Observabke(){
if (typeof this.result === 'undefined') {
return this.service.call().map(res=>res);
}
// This is code in component.
componentMethod(){
return this.service.ServiceMethod()
.subscribe(response => {
this.result = response;
},
()=>//handle error,
() => // call completed { return this.result; // Subscriber});
}
return this.weeklyPlayer; // MyCustomObject (This return won't wait for http to get completed. Not sure why you want multiple returns.)
}
Hope this helps.