Display a table dynamically depending on the option selected from a dropdown menu using

Two dropdown lists are available, with one returning an array of objects once a value is selected from it.

I am looking to dynamically display the table when the selection occurs.

 <li class="mat-form-field--inline">
  <mat-form-field>
    <mat-label>Select Application Reference</mat-label>
    <select
      [(ngModel)]="selectedObject"
      (change)="getFammille($event.target.value)"
      matNativeControl
    >
      <option
        *ngFor="let application of applications; let i = index"
        [value]="applications[i].reference"
      >
        {{ application.reference }}
      </option>
      &lt;/option>
    </select>
  </mat-form-field>

  <mat-form-field>
    <mat-label>Select a family</mat-label>
    <select
      [(ngModel)]="familyName"
      (change)="getCaracteristiques($event.target.value)"
      matNativeControl
    >
      <option
        *ngFor="let famille of familleArray; let i = index"
        [value]="famille.nom"
      >
        {{ famille.nom }}
      </option>
      &lt;/option>
    </select>
  </mat-form-field>
</li>

// This field must be selected to display the Table
<mat-form-field>
  <mat-label>Select a family</mat-label>
  <select
    [(ngModel)]="familyName"
    (change)="getCaracteristiques($event.target.value)"
    matNativeControl
  >
    <option
      *ngFor="let famille of familleArray; let i = index"
      [value]="famille.nom"
    >
      {{ famille.nom }}
    </option>
    &lt;/option>
  </select>
</mat-form-field>

<table mat-table [dataSource]="this.caracteristiques" class="mat-elevation-z8">
  <ng-container matColumnDef="id">
    <th mat-header-cell *matHeaderCellDef>type</th>
    <td mat-cell *matCellDef="let carac">{{ carac.type }}</td>
  </ng-container>

  <ng-container matColumnDef="NumeroOrdre">
    <th mat-header-cell *matHeaderCellDef>fields</th>
    <td mat-cell *matCellDef="let carac">{{ carac.fields }}</td>
  </ng-container>

  <ng-container matColumnDef="Titulaire">
    <th mat-header-cell *matHeaderCellDef>name</th>
    <td mat-cell *matCellDef="let carac">{{ carac.name }}</td>
  </ng-container>

  <ng-container matColumnDef="UniteCertifie">
    <th mat-header-cell *matHeaderCellDef>label</th>
    <td mat-cell *matCellDef="let carac">{{ carac.label }}</td>
  </ng-container>

  <ng-container matColumnDef="Etat">
    <th mat-header-cell *matHeaderCellDef>values</th>
    <td mat-cell *matCellDef="let carac">{{ carac.values }}</td>
  </ng-container>
  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>

I am encountering an error as I haven't found a way to prevent displaying the table before selecting the second field. Is there a way to add this condition?

Answer №1

Is it beneficial to include

*ngIf="caracteristiques"
in the <table..> element?

<table  *ngIf="caracteristiques" mat-table [dataSource]="this.caracteristiques"   class="mat-elevation-z8">

An example showcasing the component with both HTML and TypeScript code would be more advantageous.

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

What is the best way to troubleshoot the TypeScript error I am encountering in my JavaScript file?

Currently experiencing a TypeScript error within a JavaScript file https://i.sstatic.net/gBzWx.png The issue is within a folder containing only one JavaScript file, and there are no Node.js or package.json files present. I have disabled the TypeScript ex ...

Having trouble installing Angular CLI using npm command

After diligently following the steps outlined in the documentation here to install the Angular CLI, I encountered an issue. Upon running the command $ npm install -g @angular/cli in an empty directory, I was met with the following error message: npm ERR! ...

The argument provided is a string type, which cannot be assigned to a parameter expecting an object with a 'results' property of type string

When attempting to pass the result.nativeEvent.message to another function, I am encountering the error: Argument of type 'string' is not assignable to parameter of type '{ results: string; } on onUnityMessageController(result.nativeEvent.me ...

Tips for choosing and filtering the preferred object in ES6

Consider this array structure: const testData = [ { group: "Team1", info: [ { key: 123, person: "Alice", type: "Football" }, { key: 456, person: "Bob", type: " ...

Creating an Angular 2 project using Maven

Can anyone guide me on how to create an angular2 typescript project with maven? Is there a way to include npm install or ng build commands in the pom.xml file for building the project efficiently? ...

Resolve the upstream dependency conflict that occurs during the installation of ng-bootstrap/ng-bootstrap

Encountering an error while attempting to install npm install --save @ng-bootstrap/ng-bootstrap. Seeking assistance in resolving this issue. npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a ...

Navigating Angular: Uncover the Secrets of Unwrapping Json Data

I need some help with parsing Json data in Angular TypeScript. The data is structured as follows: https://i.sstatic.net/H7s8q.png When calling a REST API, I want to convert a Java class object into an array of model classes. How can this be achieved? "g ...

The Vue event was triggered, however there was no response

My current project consists of a Typescript + Vue application with one parent object and one component, which is the pager: //pager.ts @Component({ name: "pager", template: require("text!./pager.html") }) export default class Pager extends Vue { ...

How to customize Material UI Autocomplete options background color

Is there a way to change the background color of the dropdown options in my Material UI Autocomplete component? I've checked out some resources, but they only explain how to use the renderOption prop to modify the option text itself, resulting in a a ...

Utilize AngularJS directives within an Angular component for enhanced functionality

I'm currently in the process of enhancing an angularjs directive to integrate it into my angular component. I have successfully set up the hybrid (ng1 + ng2) environment and have also managed to inject angularjs services into Angular and utilize them ...

I keep encountering the following error message: " ERROR Error Code: 200 Message: Http failure during parsing for http://localhost:3000/login"

My Angular Login component is responsible for passing form data to the OnSubmit method. The goal is to send form data from the front-end application and authenticate users based on matching usernames and passwords in a MySQL database. ***This login form i ...

What is the correct way to define an abstract method within a class to ensure that an IDE detects and notifies if the abstract method is not implemented

Is there a way to properly define an abstract method in an abstract class and have the IDE notify us if we forget to implement it? I attempted the following approach, but it did not work: export abstract class MyAbstractClass { /** * @abstract ...

Transforming Observable of Observable of boolean into just Observable of boolean in CanActivate

I am encountering an issue with my user settings page where only the owner should have access. I am trying to use CanActivate to enforce this restriction, but I am facing a problem. CanActivate expects the output to be either boolean or an observable of ...

Managing user permissions and access levels using Firebase

I am trying to implement Role-Based User Access Control With Firebase in order to grant access to a specific route only if the user is authenticated and an admin. I found a tutorial that explains this process: However, I am using Angular 7 and encounterin ...

Storing dates using Angular 2 and JSON for efficient data management

I've encountered a challenging issue with my Angular 2 application. I'm attempting to organize my API (MongoDB) in such a way that each new "post" added by the admin can be retrieved by date (not time) on the front end. Here's an example of ...

Angular Error: Trying to access a property on an undefined variable

I'm currently having an issue with assigning data from an API to my Angular component file. Whenever I try to assign the data to my object variable, I receive an error stating: "cannot set property of undefined." Below is the relevant code snippet: C ...

What is the best way to transform an array containing double sets of brackets into a single set of brackets?

Is there a way to change the format of this list [[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "]] to look like [" ", " ", " &qu ...

The *ngIf directive seems to be malfunctioning

My Angular 2 project with RC 4 has encountered an issue where *ngIf is not functioning as expected. Below is the code snippet for the view: View <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> ...

Load all components in advance when implementing lazy loading for individual components in routing

Utilizing standalone components in angular 17 allows for direct lazyLoading of components without the need for modules. However, a question arises on how to preload in this scenario. Previously, when lazy loading modules, the strategy used was withPreloadi ...

Obtain headers from an Excel file uploaded using the XLSX format in Angular

Is there a way to extract the first row containing name, email, and mobile as an array from an uploaded excel file? I am currently utilizing XLSX for this purpose. While I am able to retrieve the entire dataset into an array, my main goal is to only ex ...