1

I have integrated the Angular6 material data grid with server side pagination as per this link https://blog.angular-university.io/angular-material-data-table/

Here, I want to display the "No Data Found", if the data set is empty from the response. I could take the totalCount which is mapped Observable and I can print the view as below. But, ngIf does not work.

  private totalCountSubject = new BehaviorSubject([]);
  public totalCount$ = this.totalCountSubject.asObservable();
  this.totalCountSubject.next([body.data.count]);

  // View
  {{dataSource.totalCount$}} <!-- It displayes 0 or count of the row -->

   <!-- It does not work. --->
   <span *ngIf="(dataSource.totalCount$ | async) === 0 ">
     NO DATA FOUND!!!!
   </span>

Any idea why ngIf does not work in this case.

FarukT
  • 1,560
  • 11
  • 25
Muthukumar Marichamy
  • 1,175
  • 1
  • 17
  • 39

1 Answers1

1

handle the condition with nested ngIf s

<ng-container *ngIf="dataSource.totalCount$ | async as totalCount">  
   <span *ngIf="totalCount == 0 ">
     NO DATA FOUND!!!!
   </span>

<ng-container>
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80