Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
Displaying No Records Found in Angular 2

I have been searching and wondering if there is any directive to help display " No data found " in a table when the table is empty in angular 2. Or better still i can create that functionality in my services when i am subscribing to a fetched data ?

  <table>
    <tbody>
        <tr *ngFor="let game of Games">

         </td>
          <td>{{game.name}}</td>
          <td>{{game.type}}</td>
          </tr>


      </tbody>
</table>
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can use the newest feature from Angular 4.0.0 and to add if else statement:

<div *ngIf="Games?.length;else no_data_templ">
    <table>
        <tbody>
           <tr *ngFor="let game of Games">
                <td>{{game.name}}</td>
                <td>{{game.type}}</td>
            </tr>
        </tbody>
    </table>
</div>

<ng-template #no_data_templ>
     No daata found...
</ng-template>

Update: for Angular 2.X you can use the following approach:

<div *ngIf="Games?.length">
    <table>
        <tbody>
           <tr *ngFor="let game of Games">
                <td>{{game.name}}</td>
                <td>{{game.type}}</td>
            </tr>
        </tbody>
    </table>
</div>

<div *ngIf="! Games?.length">
     No data found...
</div>
about 4 years ago · Santiago Trujillo Report

0

Check for the length of array if there are no elements uisng length, then display it as NO DATA,

<li  *ngIf="Games?.length == 0">
    <span class="search_no_results">
       No data found 
    </span>
</li>
about 4 years ago · Santiago Trujillo Report

0

If you want to display a message saying no data found. Before the table tag check whether Games has items to iterate.

Something like this

public hasData(): boolean {
 return (this.Games != null && this.Games.length > 0);
}

Use hasData() in the template

<div *ngIf="!hasData()">No Data Found</div>
<table *ngIf="hasData()">
    <tbody>
        <tr *ngFor="let game of Games">

         </td>
          <td>{{game.name}}</td>
          <td>{{game.type}}</td>
          </tr>


      </tbody>
</table>

You can structure & style this in anyway you want.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!