Does there exist something equivalent to the async
pipe that I could use inside a component like this
@Component({
selector: \'my-component
You have to ask yourself: What do you want to achieve by avoiding the subscribe()
call? My guess is that you want to prevent keeping the subscription around and having to unsubscribe manually.
If this is the case, you just have to make sure you get an Observable that completes. Then there is no need to unsubscribe later. You can convert any Observable (finite or infinite) to one that will eventually complete.
Here is an example for your case:
method() {
this.myObservable$.take(1).subscribe(
val => doSomething(val)
);
}
The correct way really depends on what your observable does and what you want to do with the value. Angular2 http calls for example complete on their own, no need to unsubscribe!
Or if you want to call doSomething for every new value in your observable, the above solution won't fit because you only get the first value, then the observable completes. As I said, this comes down to the context of the problem.