I am struggling to implement async/await in my code to show a spinner when I click on a button and hide it once I have all the data. Below is a simplified version of what I have:
.ts:
isLoading: boolean = false;
onLoad() {
this.isLoading = true;
this.http.post(this.Aurl).subscribe(Aresponse => {
this.Aitems = Aresponse;
this.Aitems.forEach((Aitem, Aindex) => {
let Bbody = Aitem.id;
this.http.post(this.Burl, Bbody).subscribe(Bresponse => {
let Bitem = Bresponse;
this.Bitems[Aindex] = Bitem;
});
});
});
// this.isLoading = false;
}
.html:
<button (click)="onLoad()">Load</button>
<mat-progress-spinner *ngIf="isLoading" mode="indeterminate"></mat-progress-spinner>
<div *ngIf="!isLoading" >
<div *ngFor="let Bitem of Bitems">
</div>
</div>