I am trying to write a function to be able to retain the value from Observable/Subscribe or Promise/Then. Here's the scenario:
var retValue is of string type.
CallService() :return string
{
this.http.get('http://api/..').Subscribe(data=>
{
......
this.retValue = data[0] `=>value can be accessed here`
}
return this.retValue -> HOW CAN I GET THE VALUE HERE?
}
It comes as Undefined. I know it's to do with mixing sync and async calls but what if we are in a scenario where we can't directly bind it to a component but have to get a value out of it? Let's say an ANGULAR PIPE where user passes in the data, we call the service and we need to pass the data back?
Thanks guys.