Reputation: 141
Is there a way to factorize the
(places$ | async)
in
<div *ngIf="(places$ | async) === undefined">Loading...</div>
<div *ngIf="(places$ | async) === null">No data</div>
<div *ngIf="(places$ | async) != null">{{ (places$ | async) }}</div>
I indeed store an array of places in my observable, and I need to check if the observable is either undefined or null or not empty.
Best regards,
Upvotes: 2
Views: 73
Reputation: 2795
you can use *ngIf to do as follow
i wrap it in {} to be sure we get data anyway and not be affected by ngIf
<ng-container *ngIf="{ data: places$ | async} as source">
<div *ngIf="source.data === undefined">Loading...</div>
<div *ngIf="source.data === null">No data</div>
<div *ngIf="source.data !== undefined && data !== null">{{ source.data }}</div>
</ng-container>
Upvotes: 5