Conceal a table if it has no content

I am dealing with 2 tables that contain various data sets.

img01

If both of my tables happen to be empty, I would prefer them to be hidden.

img02

Is it feasible to implement this in Angular? If you have a solution for me, I would be eager to give it a shot.

Here is the snippet of code:

file.html

<div class="row" > ;
   <div class="col-12">
      <div class="card mb-4">
         <div class="card-body">
            <div class="table-responsive">
               <table class="table table-striped">
                  <tr style="background-color: #f8f9fa;">
                     <td style="width: 13%;">Opening</td>
                     <td style="width: 13%;">Highest</td>
                     <td style="width: 13%;">Lowest</td>
                     <td style="width: 13%;">Last</td>
                     <td style="width: 15%;">Trend</td>
                     <td style="width: 6%;">    Time</td>
                     <td style="width: 15%;">Day volume</td>
                     <td style="width: 10%;">Last update</td>
                  </tr>
                  <tr *ngIf="statusLine.open != 0">
                     <td>
                        {{statusLine.open | number:'1.6-6'  }}
                     </td>
                     <td>
                        {{statusLine.high | number:'1.6-6'  }}
                     </td>
                     <td>
                        {{statusLine.low | number:'1.6-6'  }}
                     </td>
                     <td>
                        <span *ngIf="statusLine.tendancySign < 0" style="color: red;">
                        {{statusLine.close | number:'1.6-6'  }}
                        </span>
                        <span *ngIf="statusLine.tendancySign >= 0" style="color: green;">
                        {{statusLine.close | number:'1.6-6'  }}
                        </span>
                     </td>
                     <td class="no-wrap">
                        <span *ngIf="statusLine.tendancySign < 0" style="color: red;">
                        <span
                           style="background:url(/assets/images/toto-online-sprites.png)  1px -834px no-repeat;position:relative;top:5px; display: inline-block;">&nbsp;&nbsp;&nbsp;</span> {{statusLine.tendancyPercent
                        | number:'1.2-2' }}
                        </span>
                        <span *ngIf="statusLine.tendancySign >= 0" style="color: green;">
                        <span *ngIf="statusLine.tendancySign > 0"
                           style="background:url(/assets/images/toto-online-sprites.png) -296px -834px no-repeat;position: relative;top:5px; display: inline-block;">&nbsp;&nbsp;&nbsp;</span> {{statusLine.tendancyPercent
                        | number:'1.2-2' }}
                        </span>
                        &nbsp;%
                     </td>
                     <td>
                        {{statusLine.heure | getXFirstElements:'5'}}
                     </td>
                     <td>
                        {{statusLine.volume | number:'1.0'  }}
                     </td>
                     <td>
                        {{statusLine.update | getXFirstElements:'5'}}
                     </td>
                  </tr>
               </table>
            </div>
            <ng-container *ngIf="statusLinesII.length > 0">
               <div class="table-responsive">
                  <table class="table table-striped">
                     <tr style="background-color: #f8f9fa;">
                        <td style="width: 20%;" class="text-right">
                           <span> Number of buyers   </span>
                        </td>
                        <td style="width: 16%;" class="text-right">
                           <span> Bid size   </span>
                        </td>
                        <td style="width: 10%;" class="text-right">
                           <span> Limit bid  </span>
                        </td>
                        <td style="width: 6%;"> </td>
                        <td style="width: 10%;"> Limit ask </td>
                        <td style="width: 16%;" class="text-right">
                           <span> Quantity ask   </span>
                        </td>
                        <td style="width: 20%;" class="text-right">
                           <span>Number of sellers </span>
                        </td>
                     </tr>
                     <tr *ngFor="let line of statusLinesII">
                        <ng-container *ngIf="canShowLine(line)">
                           <td style="border: 0px;" class="text-right">
                              <span>
                              {{line.acheteurNumber  }}
                              </span>
                           </td>
                           <td style="border: 0px; text-align: right;">
                              <span>
                              {{line.acheteurQty  }}
                              </span>
                           </td>
                           <td style="border: 0px; text-align: right;">
                              <span>
                              {{line.acheteurCours | number:'1.6-6'  }}
                              </span>
                           </td>
                           <td style="border: 0px;text-align: right;">
                              <span>
                              {{line.vendeurCours | number:'1.6-6'  }}
                              </span>
                           </td>
                           <td style="border: 0px;text-align: right; ">
                              <span>
                              {{line.vendeurQty }}
                              </span>
                           </td>
                           <td style="border: 0px;" class="text-right">
                              <span>
                              {{line.vendeurNumber  }}
                              </span>
                           </td>
                        </ng-container>
                     </tr>
                  </table>
               </div>
            </ng-container>
         </div>
      </div>
   </div>
</div>

A thorough search on google did not yield any concrete solutions for my issue.

Your assistance is greatly appreciated!

Answer №1

To implement conditional rendering in the first table, you have two options:

<div class="table-responsive" *ngIf="statusLine && statusLine.indexOf('open') !== -1">

Alternatively, you can assign a variable to Object.keys() method in the component and use it like this:

Html:
<div class="table-responsive" *ngIf="statusLine && objectKeys(statusLine).length > 0">

Ts:
objectKeys = Object.keys;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigate directly to the dashboard page in Angular 5 using RxJS without needing to load the main page first

Utilizing Firebase as the API in my application for authentication, database management, and storage. Implemented a main page (localhost:4200) that loads when the user is not logged in, and a dashboard (localhost:4200/dashboard) for authenticated users. ...

I am encountering an error in TypeScript stating that a property does not exist on the Response type

Hey there, I've been working on a custom advanced results page that allows for various queries like /articles?name="". This is my first time using TypeScript and while migrating my code over, I encountered a TypeScript error at the very end. // esli ...

Using the setupFiles option to set up files and execute code prior to running tests

I need to ensure that some code is executed before all tests are run. My jest.config.js setup: // truncated... setupFilesAfterEnv: [ "./jest.setup.ts" ] The content of jest.setup.ts: async function setUp() { const first = new Prom ...

Having trouble retrieving the chosen option from a select box in Angular 8

I'm working with a dynamic array and I need to generate a select box based on its values. Additionally, I want to pre-select the option that corresponds to the value defined in the array. { "data": [ { "player settings": [ { ...

Discovering the number of items that have been filtered in isotope-layout using React and Typescript

Currently, I am utilizing the isotope-layout library within a React (Typescript) project. Although I have successfully implemented filtering on my page, I am unsure of how to retrieve the count of the filtered items. Upon loading the page, Isotope is init ...

No recommended imports provided for React Testing Library within the VS Code environment

I am currently in the process of setting up a Next JS project with Typescript integration and utilizing React Testing Library. Unfortunately, I'm facing an issue with getting the recommended imports to work properly within my VS Code environment. To i ...

Liferay's JavaScript bundler does not automatically remove unused node modules

Within my work on Liferay 7.3.5 and developing an Angular Portlet, I have encountered a frustrating issue. When experimenting with different modules or versions of the same module, I noticed that the final jar OSGI module contains all the modules I have in ...

Uploading CSV files in Angular 4

I am currently working on an Angular4 project where I have implemented a feature that converts data into a CSV file with a header. Now, I am looking to reverse this process and allow users to upload a CSV file instead. To test this functionality, I create ...

Modifications made in SQL are not reflected in Angular when using .NET Core

I recently encountered a challenge with my project, which is built on .NET Core 3.1 and Angular 7. After migrating the project to a new server, I started experiencing issues related to data synchronization between SQL database changes and the Angular compo ...

Using Default Parameters in the ngrx getWithQuery() Function

Curiosity strikes me on how to send the default data already present in getWithQuery(), just like this: @Injectable({providedIn: 'root'}) export class CompaniesDataService extends DefaultDataService<Company> { private readonly _URL: str ...

"Unlock the power of NGXS by leveraging the raw state values

I'm having trouble locating an example in the NGXS documentation that demonstrates how to properly type the state object. Specifically, I am looking for guidance on typing the return value of the snapshot method of Store. For instance: this.store.sn ...

Guide on retrieving the interface property name or key name as a string in Typescript

Currently, I am utilizing the API of Slack and encountering situations where I send JSON requests containing strings that return as property names later on. I want to create an interface where I can send one of its property names as a string and receive t ...

Ways to delete a class in typescript

There's a menu on my website with li tags containing an a element for navigation. Everything is working fine, but I'm facing an issue where I need to remove all elements with the class seleccionado and only add it to the clicked li. I tried using ...

Angular downgrades from version 13.3.8 to 13.3.7

When I input the command: ng v I am shown the version as "Angular: 13.3.8" in the image. Can someone explain where this version is coming from and how can I change it back to 13.3.7? Furthermore, I noticed that the packages listed in the screenshot are d ...

Coding with Angular 4 in JavaScript

Currently, I am utilizing Angular 4 within Visual Studio Code and am looking to incorporate a JavaScript function into my code. Within the home.component.html file: <html> <body> <button onclick="myFunction()">Click me</button> ...

Is your current Angular 2 project in need of data retrieval from a SQL server?

Currently, I am facing a challenge with my Angular 2 application as I am unable to connect and send queries to an existing SQL server. It has come to my attention that in order to achieve this, I need to create a RESTful API using 'express.js'. I ...

Having trouble installing memlab using the npm package

Recently, I made an attempt to install the memlab library from Meta's GitHub. Initially, when I installed it without using the -g flag, the installation was successful. However, I encountered an issue where I could not execute any of the memlab comman ...

Tips for updating the styles within a class for Angular 6 dynamically

Currently, I am able to update the button design using ng-container. Here is a snippet of the code: <ng-container *ngIf="isDisabled;"> <button class="bot-btn-disabled" (click)="confirm()" [disabled]=this. ...

Tips for identifying a pair of numbers (with varying ranges) in which one number must be present at all times

I am currently trying to understand the regex I have implemented in Angular 2 using Typescript: /[0-5]?[0-9]?/ Surprisingly, this regular expression works flawlessly to match any valid minute from 1 to 59, even though it seems like an empty string would ...

The Intl.DateTime formatter consistently generates incorrect times even after refreshing the component in a React application

Our component is responsible for receiving information from the backend and rendering it. The properties of the component are defined as: interface CitizenshipProps { citizenship?: Citizenship; name?: string; lastName?: string; onUpdateClic ...