I have noticed something about Observables in Angular 2 that I cannot explain and hope a good sould sheds light on me.
My understanding was that when subscribing to an Observable you have basically two strategies to consume the value it emits:
stream combined with async pipe, as in:
myTextSubscription$ = SomeObservable.subscribe();
{{ myTextSubscription$ | async }}
or extract the value and bind it from within the subscribe handler:
myTextSubscription$ = SomeObservable.subscribe(text => this.text = text);
{{ text }}
Well, the problem is that I have already tried a couple of times to use the latter approach and I never managed to get the text
value updated, unless I invoke this.cdRef.markForCheck()
within the handler. I guess invoking the changeDetection manually should not be required for such a basic scenario - at least I haven't seen that used in any of screencasts or tutorials.
Does this sound familiar to anyone? Is it my wrong understanding of the method, or is it perhaps a bug in Angular 2?
Edit:
The code above has been abstracted as I believed the problem could be explained on a more abstract level.
I cannot recall the first case when it bit me, but now the Observable comes from ngrx store, so it's basically something along these lines:
this.text$ = store.let((state$: Observable<State>) => {
return state$.select(state => state.text);
});