Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda