Angular - Show a table of items from a given list

I recently started using Angular and I'm facing a challenge in displaying multiple tables based on a list of values. Each rule refNo should have its own separate rule conditions table displayed sequentially. Currently, all the tables are showing the same values.

RuleComponent.html

<div *ngFor="let x of automation_rules_list">

  <table class="table">
    <thead>
      <tr>
        <th>Ticket Field</th>
        <th>Operator</th>
        <th>Expected Value</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let o of automation_rules_conditions_list">
        <td>{{o.ticketField}}</td>
        <td>{{o.ticketField}}</td>
        <td>{{o.operator}}</td>
        <td>{{o.expectedValue}}</td>
        <td><span class="pointer text-danger"><i class="fas fa-trash-alt"></i></span></td>
      </tr>
    </tbody>

  </table>

RuleComponent.ts

ngOnInit() {

  this.loadAutomationRules();
}


loadAutomationRules() {

  this.ars.getAutomationRules().subscribe(res => {

    this.automation_rules_list = res;

    for (var i = 0; i < this.automation_rules_list.length; i++) {

      this.loadAutomationRuleConditions(res[i]["refNo"]);

    }


  });

}

loadAutomationRuleConditions(ruleRefNo) {

  this.ars.getAutomationConditions(ruleRefNo).subscribe(res => {

    this.automation_rules_conditions_list = res;


  });


}

Answer №1

Make sure to include the automation_rules_condition property within each automation_rule. loadAutomationRules() {

  this.ars.getAutomationRules().subscribe(res => {

    this.automation_rules_list = res;

    for (var i = 0; i < this.automation_rules_list.length; i++) {

      this.loadAutomationRuleConditions(res[i]);

    }


  });

}

loadAutomationRuleConditions(rule) {

  this.ars.getAutomationConditions(rule["refNo"]).subscribe(res => {

    rule.automation_rules_condition = res;


  });

}

Remember to utilize x.automation_rules_condition in order to present the table.

<div  *ngFor="let x of automation_rules_list">

    <table class="table">
      <thead>
        <tr>
          <th>Ticket Field</th>
          <th>Operator</th>
          <th>Expected Value</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        <tr  *ngFor="let o of x.automation_rules_condition">
          <td>{{o.ticketField}}</td>
          <td>{{o.ticketField}}</td>
          <td>{{o.operator}}</td>
          <td>{{o.expectedValue}}</td>
          <td><span class="pointer text-danger"><i class="fas fa-trash-alt"></i></span></td>
        </tr>
      </tbody>

    </table>
</div>

Answer №2

Make sure to append the new data to automation_rules_conditions_list without overwriting it

If my response aligns with your needs, I have some recommendations for Rxjs


RuleComponent.ts

ngOnInit() {

  this.loadAutomationRules();
}


loadAutomationRules() {

  this.ars.getAutomationRules().subscribe(res => {

    this.automation_rules_list = res;

   // clear automation_rules_conditions_list
   this.automation_rules_conditions_list = [];

    for (var i = 0; i < this.automation_rules_list.length; i++) {

      this.loadAutomationRuleConditions(res[i]["refNo"]);

    }


  });

}

loadAutomationRuleConditions(ruleRefNo) {

  this.ars.getAutomationConditions(ruleRefNo).subscribe(res => {

    // append the new data to automation_rules_conditions_list
    this.automation_rules_conditions_list.push(res);


  });


}

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

How can I verify the validity of a regular expression in Typescript without encountering a syntax error?

I am facing an issue with my code where I load a set of regular expressions from an external source. My goal is to determine if a given string is a valid regex without causing the application to crash due to a syntax error. Despite trying to use try/catch ...

Implementing Ionic Native Player for Practical Applications

Looking for a way to incorporate a lightweight mp3 file into my Ionic App, I decided to utilize Native Audio from Ionic. Despite my best efforts, the solution did not function properly on the iOS emulator when called from /MyIonicApp/src/pages/home/home.ts ...

The Order ID field in the Serenity-Platform's Order Details tab is not registering orders

I've been working on replicating the functionality of Orders-Order detail in my own project. https://i.stack.imgur.com/Bt47B.png My custom module is called Contract and Contract Line item, which I'm using to achieve this. https://i.stack.imgur ...

I am unable to process the information and transform it into a straightforward list

When using ngrx, I am able to retrieve two distinct data sets from storage. private getCatalog() { this.catalogStore.select(CatalogStoreSelectors.selectAllCatalogsLoadSuccess) .pipe( takeWhile(() => this.alive), take(1), ...

Unable to generate a store using reducer in TypeScript and Redux

I am having trouble creating a store using Redux and TypeScript. Here is my actions.js file: import { Action } from 'redux'; export interface ITodoAction extends Action { todo:string; } export const ADD_TODO:string = 'ADD_TODO'; ...

Encountering issues with loading Angular formControl

I've been going through an Angular tutorial on forms, which you can check out here. In my 'datasources.component.html' file, I have the following code: <form [formGroup]="queryForm"> <label>Query: <input type="text" formCont ...

Utilize the TypeScript Compiler API to extract the Type Alias Declaration Node from a Type Reference Node

Currently, I am utilizing ts-morph library which makes use of the TS Compiler API. Here is an example of my code: export type Foo = string export const foo: Foo = 'bar' Whenever I try to find the type for the export of foo, it returns string. H ...

OpenAPI implementation in NestJS that emphasizes the use of reusable parameters

Is it possible to reuse common parameters in the implementation of NestJS OpenAPI/Swagger? This feature would prevent me from having to clutter my endpoint with repetitive @ApiImplicitQuery decorators. ...

Ways to access information from a service prior to making database changes in Angular 2?

Here is my inquiry. I have a component that allows users to click a favorite button. This action updates the "favorite" column in the database. To update this value, I retrieve it from the database using the following steps: - Upon initializing the compon ...

issue with uploading files in angular 7

Currently, I am facing an issue with Angular 7 where the input type "file" is not working as expected. However, in Angular 6, everything works fine. When submitting the input file type data in Angular 6, I receive a field list like this: https://i.sstat ...

Angular: Issue with canActivate not functioning properly when using redirected routes

My application's router file is set up with the following routes: export const router: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', canActivate: [AuthGuar ...

What is the process for transmitting an array of objects from Angular to a Web API Core using HttpGet?

In my TypeScript file, I have an array of objects called PropertiesParams: const PropertiesParams = [{ Name: 'FirstName', Filter: 'Like1' }, { Name: 'LastName', Filter: 'Like2' }, { Name: ...

When the value of a react state is used as the true value in a ternary operator in Types

Attempting to implement sorting on a table is resulting in the following error: (property) direction?: "asc" | "desc" No overload matches this call. Overload 1 of 3, '(props: { href: string; } & { active?: boolean; direction? ...

Exploring TypeScript: A Study on Interfaces and Abstraction

I am working with TypeScript and have created four different entities (models) as shown below: Base model definition: export interface BaseModel { id: string; entityId: string; entityName: string; } Child Model 1: import { BaseModel } from ' ...

Typescript - filtering out null values from JSON object

I am facing an issue with my service method that saves a date on the server. When this method sends the date to the server, it includes fields with null values in the JSON. How can I exclude these fields with null values? public create<T>(post: any) ...

Angular interceptor allows the execution of code after the outgoing request has completed its process

In the process of creating a simple interceptor, I have encountered an issue. The interceptor is designed to check if an outgoing request is targeting a specific endpoint type, namely events and favoriteevents. While the interceptor works almost as intend ...

When retrieving data from MongoDB, an error occurs stating "Unable to read the property 'firstname' of null."

I've been working on retrieving user information from MongoDB and displaying it through HTML, but I keep encountering an error that says: "Cannot read property 'firstname' of null." For my backend service, I'm using Express and Node.js, ...

How to focus on an input element in Angular 2/4

Is there a way to focus on an input element using the (click) event? I'm attempting to achieve this with the following code, but it seems like there may be something missing. (I am new to Angular) sTbState: string = 'invisible'; private ele ...

The password field value in an Angular form is not defined

After making some modifications to a sign-in template that worked perfectly before, I encountered an error when trying to submit the signup form. The error message reads as follows: ERROR TypeError: Cannot read property 'value' of undefined Here ...

How can Typescript help enhance the readability of optional React prop types?

When working with React, it is common practice to use null to indicate that a prop is optional: function Foo({ count = null }) {} The TypeScript type for this scenario would be: function Foo({ count = null }: { count: number | null }): ReactElement {} Wh ...