I have an observable (or subject) in an angular 4 component, and I'm using that in the template with an async
pipe, something like this:
<div *ngIf="(orderObservable | async) as order; else noOrder ">
The active order was created at {{ order.created_at }}
</div>
<ng-template #noOrder>
There is no active order at the moment. Sorry.
</ng-template>
This works like a charm as long as the order does not exist, or is retrieved via HTTP call. In the code this looks something like this:
this.orderObservable = OrderService.getActive();
If this call returns an observable with an order, it gets displayed in the template. If it doesn't, the #noOrder template is displayed.
Now my question is: If I change the observable to a subject, and the currently active order does not exist anymore (i.e. because it was submitted or closed), is there any way to delete the subject, or pass something into the subject, so the template displays the #noOrder template instead of the one that displays the observable content, after it displayed the latter already?