I just started with an Angular 2 app that makes some http calls and this introduced me with Observables. I am still having a hard time in learning how to deal with them, the documentation is a bit lacking for beginners. I'll give a short example to illustrate the difficulties that I encounter:
getValue() {
let headers = new Headers({ 'Content-Type': 'text/plain' });
let options = new RequestOptions({ headers: headers });
return this.http.get('http://url/boolean.json', options)
}
This is a get call that returns a boolean value. Now if I would want to use this value in a function I instinctively would expect that I could assign a variable like this:
let varName = this.getValue()
Obviously this isn't possible, I read that in order to get output from an observable you need to subscribe to it. Isn't there a possibility to let my function getValue() return a boolean and not an observable? In this case however, since I only need to have boolean value, I am not sure if asynchrounous programming makes sense? It's not as if this can take a long time. Is there also a way in Angular 2 to get rid of this asynchronous behavior (for simple functions like this?)?