Leveraging the power of multiple ngFor directives within table components

I am working on a task to present the data fetched from my GET API in JSON format in a tabular layout. Additionally, I want to include a search functionality for this table using a pipe. The code snippet I have written is as follows:

html

    <div class="row" *ngIf="!addNewConfig">
    <div class="col-xs-2">
        <div class="form-group margin-b0px">
            <label class="float-label with-icon" [class.empty]="searchField.length==0">
                <span class="placeholder">Search a Config.
                    <span class="hide-placeholder">&nbsp;</span>
                </span>
                <input [(ngModel)]="queryString" type="text" class="search">
            </label>
        </div>
    </div>
    <div class="col-xs-1 pull-right text-right clickable">
        <img src="dvn/images/plus-icon.png" alt="Add" (click)="addNewConfig = true;">
    </div>
</div>
<ng-container *ngIf="!addNewConfig">
    <table *ngIf="!additionalInfo" class="primary-table table table-hover">
        <thead>
            <tr>
                <th>Config NAME</th>
                <th>NO. OF SOURCES</th>
                <th>SRC NAME(S)</th>
            </tr>
        </thead>
        <tbody>
            <tr *ngFor="let n of names | FilterPipe: queryString">
                <td>
                    <a (click)="addtionalInfo = true" class="clickable">{{n}}</a>
                    <button (click)="getData()"> Test Get Request</button>>
                </td>
                <td>2</td>
                <td>CardTransStream, SampleText1</td>
            </tr>
        </tbody>
    </table>

The fetched JSON data is stored in the variable getdata and has the following structure:

 [{
  "configName": "config1",
  "queryTimeThresholdInMs": 0,
  "sources": [
    {
      "baseline": true,
      "order": 0,
      "query": "string",
      "sourceId": "string",
      "sourcePath": "string",
      "sourceType": "string"
    },
        {
      "baseline": false,
      "order": 1,
      "query": "string",
      "sourceId": "string",
      "sourcePath": "string",
      "sourceType": "string"
    }
  ]
  },
{
  "configName": "config2",
  "queryTimeThresholdInMs": 0,
  "sources": [
    {
      "baseline": true,
      "order": 0,
      "query": "string",
      "sourceId": "string",
      "sourcePath": "string",
      "sourceType": "string"
    },
      {
      "baseline": false,
      "order": 1,
      "query": "string",
      "sourceId": "string",
      "sourcePath": "string",
      "sourceType": "string"
    }
  ]
}]

I'm looking for a way to incorporate an ngFor loop in the table structure to display the configName along with other details such as the number of sources and source name in a tabular form without affecting the existing ngFor loop that enables searching by configName.

Answer №1

To efficiently loop through getdata and its corresponding sources, try using a structure like the following:

<div *ngFor="let mem of getdata "> 
    {{mem.configName}}
    <div class="card-container">
      <div *ngFor="let source of mem.sources">
        {{source.query}}
      </div>
    </div>
</div>

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

Understanding how to efficiently pass a prop from one child to another using React Hooks

I'm facing a challenge in passing a unique id prop from one child component to another within my React application. The scenario involves three components: Homepage as the parent, and two direct children called Gallery and Detail. The Gallery compone ...

Utilizing JavaScript libraries in a TypeScript project: A step-by-step guide

Currently, I am working on an existing TypeScript AngularJS project and looking to incorporate d3js. However, due to restrictions with the corporate proxy, I am unable to use tools for downloading or managing dependencies. As a result, I have opted for man ...

Potential absence of the object has been detected after performing object verification

I encountered an issue with the following error message: Object is possibly 'undefined'.ts(2532) This is what my configuration looks like: export interface IDataColumns { name: string; label: string; display: string; empty: boolean; fi ...

The identification of the field is not being transmitted by ng-select

Looking for help with Angular! I have an ng-select box where I can choose countries, and it's working fine when I select an option and submit - it submits the id as expected. However, when pre-populating the ng-select with data and submitting, it&apos ...

Changing the language can lead to an ExpressionChangedAfterItHasBeenCheckedError when the translated value is found within a mat-option

Choose a value from the dropdown menu, then toggle the switch button. An error message labeled 'ExpressionChangedAfterItHasBeenCheckedError' will appear in the console. Click here for an example This issue cropped up after upgrading my Angular ...

Tips for including additional properties to a <button> element using ReactJS and Typescript

Currently, I am in the process of creating a unique component which consists of an ordinary <button> tag and has a new prop called aria-current. The issue at hand is that Typescript is flagging an error stating that this property does not exist with ...

Are there any alternative methods to define a constructor function in TypeScript that do not involve utilizing classes? Upon researching on this subject, it appears that all sources suggest using classes

Is it possible to transform this class declaration into a constructor function without losing TypeScript compatibility? class Animal { constructor(public name: string, public energy: string) {} } ...

What is the proper way to utilize bootstrap dropdown menus?

I need to create a dropdown menu similar to the one shown in this image: https://i.sstatic.net/SXDgy.png https://i.sstatic.net/wVbnd.png I attempted to use code from the following URL: https://getbootstrap.com/docs/4.0/components/dropdowns/, but unfortun ...

Tips for preventing the creation of .d.ts.map files while using tsc to exclusively generate declaration files

When I create a build using tsup, I encounter numerous errors with the dts option. The official tsup documentation also mentions that typescript declarations generated by tools other than tsc may not be perfect. As a result, I have decided to use tsc for ...

Can the default setting for --base-href be configured specifically for ng build and not for ng serve?

How can the default setting of --base-href for ng build be adjusted without impacting ng serve? Utilizing Angular CLI version 1.6.6 Compatible with Angular 5 and above ...

The latest release of Angular2, rc1, eliminates all parameters that are not in

In the previous beta version, I was able to analyze using split Location.path(), but now it seems to have been removed. How can I prevent this removal? Interestingly, everything works well with matrix parameters (;id=123;token=asd). This was tested on a ...

Typescript iterative declaration merging

My current project involves creating a redux-like library using TypeScript. Here is an example of the basic action structure: interface ActionBase { type: string; payload: any; } To customize actions for different types, I extend the base interface. ...

No errors found in Angular Reactive Forms FormGroup

When working with Reactive Forms, a formGroup containing invalid FormControls appears as invalid without any errors specified. Even though the form is invalid, accessing formGroup.errors returns null. Each invalid formControl does provide validation error ...

Generate a <mat-error> element dynamically and ensure it is correctly projected into the parent <mat-form-field> component

Creating a component dynamically using the ComponentFactoryResolver is relatively simple, but I have encountered an issue when attempting to project the created component into its parent when working with the Angular Material <mat-error> component in ...

Support for ng-template in Android is not available in NativeScript with Angular

Is there a way to display a List View With Custom Row item in Native Script on a new page by utilizing Xto to inflate List View? I'm encountering an issue where the ng-template for List Item is not being recognized by the native script on my App. < ...

What is the best way to make an Angular Material checkbox respond to a programmatic change in value within a reactive form?

I have implemented a dynamic angular form that allows users to add rows using a button. I am currently working on adding functionality to select all rows. Each row includes a checkbox that toggles the value in the object between T and F. If all checkboxes ...

Utilizing models to establish the data type of an Observable within Angular

I have a simple query regarding a service. I have a method called getAllArticlesFromDb in my service that retrieves data from an API using an HTTP GET call. Here is the code for the method: article.service.ts getAllArticlesFromDb() : Observable<any> ...

In order to run Selenium Web Driver (specifically for Angular and Protractor), you will need to have the beta version of

Encountering an issue when attempting to run end-to-end tests in a freshly created Angular application: Error: SessionNotCreatedError: session not created - ChromeDriver version 90 only supports Chrome version 90 The chromedriver=90.0.4430.24 seems to be ...

The installation of @types/jquery leads to an unnecessary global declaration of $

In my package.json file, I have the following dependencies defined: { "dependencies": { "@types/jquery": "^3.5.5", } } This adds type declarations through @types/jquery/misc.d.ts, including: declare const jQuery: JQue ...

Save Component Characteristics in a type-safe array

Is it possible in Svelte to define a strongly typed array that matches the properties exported by a specific component? For instance, if I have the following code snippet, const things = [], is there a way for Svelte to recognize that each item within the ...