How to handle boolean observables with the async pipe in Angular
Here's a way where you can share the subscription and not have to make any custom pipe:
<ng-container *ngIf="{value: obs$ | async} as context">
{{context.value}}
</ng-container>
The *ngIf
will evaluate to true
no matter what (I believe) and then you can do your own tests on the value
in the context
object.
...would be better if they would just implement *ngLet
I think!
The thing I like about this solution is that the resulting value is reusable with only the single use of an async
pipe and its still pretty concise (even if it isn't perfect).
You can do (obs$ | async) !== null