angular - 如何将微调器与 *ngFor async 一起使用
问题描述
我有一个疑问,在 angular v4 之后,我们必须pipe async
在*ngFor
没有subscribe
. 在此之前,我总是使用一个变量布尔值在开始请求时显示微调器,并在获得响应时删除!现在有了async
,我怎么能在没有订阅的情况下做到这一点?什么是最好的方法?我试过了:
users: Observable<User[]>
<ion-spinner *ngIf="!users" class="spinner" name="circles"></ion-spinner>
<ion-list no-lines>
<button ion-item *ngFor="let user of users | async" (click)="onChatCreate(user)">
{{ user.name }}
</button>
</ion-list>
但是不工作......有人有帮助的想法吗?非常感谢!
解决方案
您可以使用ngIf..else
如下所示
<div *ngIf="ovservable$ | async as user; else loading">
</div>
<ng-template #loading>
Loading...
</ng-template>
在这里检查:NgIf