display a table using angularjs only if the table contains at least one row

I am currently developing a web application using MVC5 and AngularJS. The main component of my app is a table.

<div class="table-responsive scroll" ng-hide="hidetable">
    <table id="table" class="table table-bordered table-condensed">
         <thead>
              <tr class="bg-primary">
                  <th><a href="#" class="erp-tb-a" ng-click="order('date')">Date</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('day')">Day</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('brandname')">BrandName</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('zone')">Zone</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('location')">Location</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('area')">Area</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('trainer')">TrainerName</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('program')">Program</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('trainingno')">Training Id</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('amount')">Amount</a></th>
                  <th><a href="#" class="erp-tb-a">Remark</a></th>
                  <th><a href="#" class="erp-tb-a" ng-click="order('sonvinid')">SonvinId</a></th>
                  <th><a href="#" class="erp-tb-a" ></a>Add</th>
              </tr>
              <tr class="bg-primary">
                  <td><input type="text" class="erp-input" ng-model="search.date" /></td>
                  <td><input type="text" class="erp-input" ng-model="search.day" /></td>
                  <td><input type="text" class="erp-input" ng-model="search.brandname" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.zone" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.location" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.area" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.trainer" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.program" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.trainingno" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.amount" /></td>
                   <td><input type="text" class="erp-input" /></td>
                   <td><input type="text" class="erp-input" ng-model="search.sonvinid" /></td>
                   <td></td>
              </tr>
          </thead>
          <tbody>
              <tr ng-repeat="p in getallcompany | orderBy:predicate:reverse | filter:search">
                  <td>{{p.date}}</td>
                  <td>{{p.day}}</td>
                  <td>{{p.brandname}}</td>
                  <td>{{p.zone}}</td>
                  <td>{{p.location}}</td>
                  <td>{{p.area}}</td>
                  <td>{{p.trainer}}</td>
                  <td>{{p.program}}</td>
                  <td>{{p.trainingno}}</td>
                  <td>{{p.amount}}</td>
                  <td><input type="text" class="erp-input" style="width:90%; border:1px solid black;" ng-model="mdremarks" /></td>
                  <td>{{p.sonvinid}}</td>
                  <td><md-checkbox tabindex="0" area-label="none" role="checkbox" ng-click="clickcheckbox()"></md-checkbox></td>
               </tr>
           </tbody>
  </table>
  <div style="margin-bottom:20px">
       <a href="#" style="cursor:pointer;" class="btn btn-primary active">Generate Bill</a>
       <a href="#" style="cursor:pointer;" class="btn btn-warning active">Back</a>
   </div>


</div>

Here's the scenario I'm dealing with regarding the visibility of the table:

ng-hide="hidetable"

If the table is empty, meaning no rows are returned from the SQL query, it should be hidden. If there are rows returned, the table should be displayed.

var app = angular.module('myapp', ['ngMaterial']);
app.controller('mycontroller', function ($scope, $http) {
            $scope.hidetable = true;

In my controller, I've initially set the table to be hidden on page load.

$http.get('/freezeservice.asmx/gettabledetails', {
                params: {
                    log: log,
                    pm: pm,
                    comname: $scope.mdcompany,
                    mm: $scope.datemm,
                    yy: $scope.dateyy
                }
            })
                .then(function (response) {
                    {
                        $scope.getallcompany = response.data.info;

                    }
                });

This is how I retrieve the data for populating the table.

Your assistance would be greatly appreciated.

Answer №1

To implement conditional rendering in Angular, simply include the ng-if directive. Alternatively, you can also utilize ng-show and ng-hide

<table ng-if="getallcompany.length">

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

An Issue with Ionic Modal Dismissing

During the development of a small app, I encountered an interesting "bug" that I believe is worth mentioning here. The issue revolves around a modal that contains a simple login form. Upon submitting the form data, it triggers the login() method as shown i ...

Enhanced jQuery Embed Code validation for user input using a textarea

Currently, I am developing a website that allows users to input embed codes from popular platforms such as Twitter, YouTube, Instagram, Facebook, and so on. The embed code undergoes validation checks and is saved if it meets the criteria. However, when us ...

How can I retrieve the value of $_POST[] immediately after a selection is made in a dropdown box

Is there a way to retrieve the $_POST value immediately after changing the select option without having to submit the form? <select name="cat_id" class="form-control" onChange="this.form.submit();" style="width:300px;"> <?php ...

Ways to retrieve the identifiers of every child node UL element within a UL container

I am struggling with a basic question related to HTML structure. Here is the code snippet I am working with: <ul> <li> <ul class=t2 id=15> <li class='item'>a<span class='val'>b</ ...

Error encountered while attempting to create a non-unique index in SQL Server due to an existing unique

As I am attempting to add a non-unique index to a table in SQL Server 2005, I encountered an error during the creation process. Upon executing the CREATE UNIQUE INDEX statement, I received the following message: Msg 1505, Level 16, State 1, Line 1. The ...

"Retrieve objects from an array based on specified minimum and maximum values, while also checking for any null

My current dataset is structured as follows: const data = [ { id: '11se23-213', name: 'Data1', points: [ { x: 5, y: 1.1 }, { x: 6, y: 2.1 }, { x: 7, y: 3.1 }, { x: 8, y: 1.5 }, { x: 9, y: 2.9 ...

How can I trigger a method after the user has finished selecting items in a v-autocomplete with multiple selection using Vuetify?

After multiple selections are made in a v-autocomplete, I need to trigger a method. However, the @input and @change events fire after each selection, not after the full batch of selections. Is there an event that triggers when the dropdown menu closes? Al ...

Managing time intervals and scoping challenges in a Jquery plugin

Currently, I am in the process of creating a simple JQuery plugin with a specific functionality. My goal is to pass a single element like $("div").applyPlugin(); and have it loop through each selector provided, setting an interval that is unique to that in ...

Using VeeValidate with v-menu

Has anyone been able to successfully apply veevalidate to vuetify's v-menu component? I've tried using the validation-provider container with other HTML inputs and it works fine, but when I try to integrate it with v-menu, it doesn't seem t ...

What is the mystery behind the unrecognized plugin "static-fs" mentioned in the .babelrc file?

Currently, I am attempting to execute the exhibits in my deck.gl project. After cloning the repository, navigating to the exhibits directory, and running the command: npm run browserify All packages are successfully installed without any errors. However, ...

What is the reason for requiring the size of the variable in useEffect's dependency array to remain constant during renders?

During my development process, I found an issue where the console was displaying an error whenever I changed a state and logged its value using useEffect. The error message in the console can be seen in this screenshot: image of console showing the error. ...

Exploring Meta Tags with Meteor and Angular-Ui-Router

Is it possible to control meta tags in Angular templates with Angular-Ui-Router, or include them somehow? In Meteor Angular, your app cannot be wrapped within <html ng-app="app">; instead, it must be at least wrapped within <body ng-app="app"> ...

What are the steps for updating an NPM package that was installed from a Git repository?

I'm struggling to understand how to update a package that was installed from a git repository. Let's say I have a package located at git+ssh://<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b3bda094b3bda0b8b5b6fab1 ...

:onchange event triggering iteration through a function

My Vue.js application is experiencing issues with infinite post requests when a selectbox value changes. I have a table component that needs to display students from different 'tutorgroups'. Each tutorgroup, like '4M07a', has its own se ...

Picture in the form of a radio button

Is there a way to use an image instead of a radio button in my AngularJS form? I have managed to hide the radio button using CSS, but it disables the checked event. How can I make the image clickable? position: absolute; left: -9999px; Here is the code s ...

The Powerful Duo: JavaScript and Regex

Having some issues with the code snippet below, I know there's an error in my code but I can't seem to figure out what it is (tried enclosing the code in quotes but that didn't work...) var Regex = require('regex') var regex = new ...

Error encountered after attempting to save with incorrect configuration settings for the resource

A portion of my code involves a service module that sends data using the POST method: //services.js var myServices = angular.module('myServices', ['ngResource']); myServices.factory('User', ['$resource', function($ ...

Guide on creating windows, openings, or cutting shapes in three.js

I'm new to working with three.js and I have a project where I need to create a "room" with doors and windows. It seems like a simple task, but all the answers I've found so far are not up-to-date. Similar questions can be found here: - subtra ...

Displaying all hidden sections on a website

I'm trying to figure out if there's a way to expand all the collapsible sections on a webpage at once. One section that is relevant to my search looks like this: <tr> <td></td> <td style="..;"> <div s ...

Cross-domain scripting with JavaScript

I currently manage 2 subdomains securityservices.example.com workstations.example.com All workstations are associated with the workstations.example.com One of the workstations, known as WS789012 on the domain, is fully qualified as: WS789012.workst ...