Add custom text 'Loading..' untill data fetch from API

131 Views Asked by At

Is there any way show 'Loading' text until data fetch from api. As of now it is showing no data to display

I gone through the documentation did not found anything

1

There are 1 best solutions below

0
Evgeny Gurevich On

You can try something like below:

In .ts file:

isLoading = false;

doRequest() {
  isLoading = true;
  this.servis.doRequest()
    .pipe(finalize(() -> this.isLoading = false))
    .subscribe(data => {
     // do smth
     })
}

in .html

<div *ngIf="!isLoading; else loading">Your content</div>
<ng-template #loading>Loading...</ng-template>