I tried the below stackblitz link to display "No records found" message when there is no table data but the problem comes when I use data source of type MatTableDataSource.
stackblitz link: https://stackblitz.com/edit/angular-w9ckf8
Below is the code snippet am using:
this.serviceDataSource = new MatTableDataSource(this.services);
corresponding html:
<table mat-table [dataSource]="serviceDataSource" matSort *ngIf="serviceDataSource.length > 0">
<ng-container *ngFor="let disCol of serviceColumns" matColumnDef="{{disCol}}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{disCol}}</th>
<td mat-cell *matCellDef="let rowValue">{{rowValue[disCol]}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="serviceColumns"></tr>
<tr mat-row *matRowDef="let rowdata; columns: serviceColumns;"></tr>
</table>
<div *ngIf="serviceDataSource.length === 0">No records found</div>
Below is the error am getting:
ERROR TypeError: Cannot read property 'length' of undefined