Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a spinner when Mat-table is loading?

I load the data in my material table like that :

ngOnInit(){ return this.annuairesService.getMedecins().subscribe(res => this.dataSource.data = res);} 

I want show the spinner when is loading : <mat-spinner ></mat-spinner>

I try : showSpinner: boolean = true;

ngOnInit(){ return this.annuairesService.getMedecins() .subscribe(res => this.dataSource.data = res); this.dataSource.subscribe(() => this.showSpinner = false }   

but i have this error :

src/app/med-list/med-list.component.ts(54,21): error TS2339: Property 'subscribe' does not exist on type 'MatTableDataSource<{}>'. 
like image 819
Newbiiiie Avatar asked Jul 26 '18 08:07

Newbiiiie


People also ask

What is NGX spinner?

A library with more than 50 different loading spinners for Angular 4 - 14. ( https://napster2210.github.io/ngx-spinner/)


1 Answers

table.component.html

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">    <!-- table here ...-->    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>   <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> </table>  <div *ngIf="isLoading"     style="display: flex; justify-content: center; align-items: center; background: white;">   <mat-progress-spinner      color="primary"      mode="indeterminate">   </mat-progress-spinner> </div> 

table.component.ts

isLoading = true; dataSource = null;  ngOnInit() {     this.annuairesService.getMedecins()        subscribe(         data => {           this.isLoading = false;           this.dataSource = data         },          error => this.isLoading = false     ); } 

Live demo

like image 64
Tomasz Kula Avatar answered Sep 22 '22 04:09

Tomasz Kula