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

361
Views
Display text or table based on ngIf

I have a table that is populated based on API call response(job_list). If no data is returned, I want to display a text saying "No data". I have done the following:

HTML

<div [hidden]="!job_list.length">
<table>
.
.
.
.
.
</table>

Where should I add the text "No data"? Thank you.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can check.

 <div *ngIf="job_list.length > 0">
   // Show table
 </div>
 <div *ngIf="job_list.length === 0">No Data</div>
over 4 years ago · Santiago Trujillo Report

0

You can do this via a separate template, all it just requires is one *ngIf, with an else included. Read more about ngIf in the official docs.

<ng-container *ngIf="job_list.length; else noDataTemplate">
    <table>

    </table>
</ng-container>


<ng-template #noDataTemplate>
    <p>No data found</p>
</ng-template>
over 4 years ago · Santiago Trujillo Report

0

You can use [ngSwitch] to achieve this. More info in Angular Doc

<ng-container [ngSwitch]="job_list.length">
   <ng-container *ngSwitchCase="0">
      <p>No Data</p>
   </ng-container>

   <ng-container *ngSwitchDefault>
      <table>
    
      </table>
   </ng-container>
</ng-container>

Try it yourself on this Stackblitz

over 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!