Assume I have a certain fetch service call on ngOnInit lifecycle hook. But before that call gives response I switched to another component and came back to same first component and hence another fetch service call went.
I have a ngx-ui-loader attached to the service call. Now what heppens, the very first service call gives response so the loader stops, but UI is not updated. The UI got updated when the second service call gave response.
Hence there was some time delay between the stopped loader and the updated UI.
How to prevent this? or
How to checked if any relevent service call is already there in progress then we can again subscribe it and get response and update UI?
Code: component.ts
user:any = [];
ngOnInit() {
this.commonService.getUserList().subscribe(response => {
this.users = response.body;
});
}
component.html
<ng-container *ngFor="let user of users">
<p>{{ user }}</p>
</ng-container>