Best practice for displaying a spinner or similar with async pipe

18 views
Skip to first unread message

Jamison Roberts

unread,
May 15, 2019, 9:08:54 PM5/15/19
to Angular and AngularJS discussion
If I use async pipe in my html to handle subscribing and destroying an Observable, is there a "best practice" for displaying any sort of info while the data loads, be it a spinner or even the text 'loading...'?   I suspect not, and that I need to explicitly handle the subscription myself, but I thought I'd ask before going that direction.  

Thanks,
-Jamison

Sander Elias

unread,
May 17, 2019, 2:28:29 AM5/17/19
to Angular and AngularJS discussion
Hi Jamison,

Yes, there is a best practice for that.

Do something like this:

<p *ngIf="timer$ | async as result else loading">Timer {{result}}</p>

<ng-template #loading>loading...</ng-template>


Hope this helps,
Regards
Sander
Reply all
Reply to author
Forward
0 new messages