When the button is clicked, a fresh row will be added to the table and filled with data

In my table, I display the Article Number and Description of werbedata. After populating all the data in the table, I want to add a new article and description. When I click on 'add', that row should remain unchanged with blank fields added below it. Currently, when I add a new row, it disappears and only blank fields are generated again. Here is my code:

HTML :

<md-card class="default-card">
  <h1>{{ 'Edit Details' }}</h1>
</md-card>

<div class="flex">
  <md-card class="werbedata-details">
    <div *ngIf="werbedata">
      <md-input-container>
        <input mdInput placeholder="{{ 'Werbe Nummer' }}" [(ngModel)]="werbedata.WERBE_NR" name="WERBENR" disabled type="text">
      </md-input-container>
      <md-input-container>
        <input mdInput placeholder="{{ 'Produkt Name (Werbe Name)' }}" [(ngModel)]="werbedata.Produktbez" name="Produkt Name">
      </md-input-container>
      <md-input-container>
        <input mdInput placeholder="{{ 'Werbetext' }}" [(ngModel)]="werbedata.Werbetext" name="Werbetext">
      </md-input-container>
      <md-input-container>
        <input mdInput placeholder="{{ 'Produkt Bezeichnung' }}" [(ngModel)]="werbedata.Produktbez" name="Bezeichnung">
      </md-input-container>
      <md-input-container>
        <input mdInput placeholder="{{ 'VK-Einheit' }}" [(ngModel)]="werbedata.MGEHT" name="MGEHT">
      </md-input-container>
    </div>
  </md-card>
  <md-card class="werbenumber-list">
    <md-card-content>
      <table>
        <thead>
          <th> Artikle </th>
          <th> Description </th>
        </thead>
        <tbody>
          <tr *ngFor="let product of this.products">
            <td>{{ product.ARTNR }}</td>
            <td>{{ product.PRODUKTBEZ }}</td>
          </tr>
          <tr>
            <td>
                <input class="form-control" type="text" id="newValuesARTNR" [(ngModel)]="newValues.ARTNR" name="newValuesARTNR" />
            </td>
            <td>
                <button class="btn btn-default" type="button" (click)="addFieldValue(newValues.ARTNR)">Add</button>
            </td>
        </tr>
        </tbody>
      </table>
    </md-card-content>
  </md-card>
  <div class="endbuttons" align="end">
    <button md-raised-button (click)="goBack()">
      {{ 'cancel' }}
      <md-icon>cancel</md-icon>
    </button>
    <button md-raised-button color="primary" (click)="editWerbedata(werbedata)">
      {{ 'save' }}
      <md-icon>save</md-icon>
    </button>
  </div>
</div>

EditDetailsPage.ts

  getWerbeData(filialewerbenr) {
    this.werbedataService.getWerbeData(filialewerbenr)
      .then(
        werbedata => {
          this.werbedata = werbedata[0];
          let artns = this.werbedata.ArtNr.split(' ');
          this.anums = artns;
          for (let a of artns) {
            this.getProduktData(this.werbedata.FILIALE + a);
          }
        },
        error => this.errorMessage = <any>error
      );
  }

  // More functions...

What I am trying to do is edit all the details of Werbedata. Can someone please guide me on how to add newly added rows with articles and descriptions to my "update werbedata" method?

MyJsonObject :


0:
Aktiv_Log:""
Aktiv_Log_leer:""
ArtNr:"3323 3319 3322 3331 3309 3317 3316 3329 3330 3332 3324"
ArtNr_01:"3323"
ArtNr_01_Name:"Schoko-Krokant 2 kg"
ArtNr_01_PRZ:""
ArtNr_01_S:"H3323"
ArtNr_02:"3319"
ArtNr_02_Name:"Schoko 2 kg"
ArtNr_02_PRZ:""
ArtNr_02_S:"H3319"

and so on...

If anyone can provide input on how to achieve this, it would be highly appreciated.

Answer №1

To complete this task, you must extract the value from the form and insert it into the products array once you have generated a product object.

I have developed a sample StackBlitz project to illustrate the process. Feel free to check it out.

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

TypeScript's type 'T' has the potential to be instantiated with any type, even if it is not directly related to 'number'

Let's say we have a function that takes a value (for example, number) and a callback function that maps that value to another value. The function simply applies the provided callback: function mapNumber<T>(value: number, mapfn: (value: number) = ...

Tips for instructing kysely key-gen to utilize basic data types for mapping database tables

While using the kysely-codegen tool to automatically create all models from my database, I have noticed a peculiar behavior. It seems to be adding a Generated type to every field instead of generating only number or boolean. Any idea why this is happening? ...

Modifying a Component's Value in its Template Based on an IF Condition in Angular 6

How can I display or hide the 'separator-container' based on a specific condition in the row data? The condition to satisfy is mentioned as "myConditionCheck" in the 5th line of code. I attempted to achieve this by using "isWarningSeperatorVisib ...

Error: useRef in TypeScript - cannot be assigned to LegacyRef<HTMLDivElement> type

Struggling to implement useRef in TypeScript and facing challenges. When using my RefObject, I need to access its property current like so: node.current. I've experimented with the following approaches: const node: RefObject<HTMLElement> = us ...

When accessing from the frontend (Angular), the User.FindFirst(ClaimTypes.NameIdentifier) method does not return any values

I'm encountering a new issue - just as the title suggests. I've managed to identify where the problem occurs but I'm unable to resolve it. Let's start from the beginning. In the backend (ASP.NET 3.0), I have a class AuthController with ...

Issue with a child element that is malfunctioning because of the parent element

There seems to be an issue with the child tag link not working because of the parent tag link. Is there a solution for this problem? Please provide suggestions. Here is the code snippet: <div class="d-flex flex-wrap mx-auto mb-4"> < ...

Is there a way to avoid waiting for both observables to arrive and utilize the data from just one observable within the switchmap function?

The code snippet provided below aims to immediately render the student list without waiting for the second observable. However, once the second observable is received, it should verify that the student is not enrolled in all courses before enabling the but ...

Utilizing the power of Typescript in Express 4.x

I'm currently working on building an express app using TypeScript and here is what my code looks like at the moment: //<reference path="./server/types/node.d.ts"/> //<reference path="./server/types/express.d.ts"/> import express = requir ...

Renew expired JWT tokens using Angular 11 interceptor in conjunction with a Spring Boot backend

I have been working on a project using spring boot and angular, where users log in from the Angular frontend to the authentication API on Spring Boot to receive a JWT token. To ensure that all requests include this token, I have implemented an interceptor ...

Include the particules.js library in an Angular 4 project

I am currently working on integrating Particles.js into my Angular project, but I am facing an issue with the Json file not loading. import { Component, OnInit } from '@angular/core'; import Typed from 'typed.js'; declare var particl ...

The lack of space within the <mat-select> component is causing some issues. Is there a way to incorporate multiple lines within the <

Is there a way to display multiple lines of text for each option in mat-select, instead of limiting the characters and adding "..." at the end? I need the options to have additional description lines. Here is a StackBlitz demo showcasing my issue: https:// ...

Learn how to bring a component into another component within Angular

I have developed a component named CopySchedulefromSiteComponent and now I am looking to import it into another component called SiteScheduleComponent. However, I am unsure of the correct way to do this. The CopySchedulefromSiteComponent contains one fiel ...

"Although TypeOrm successfully generates the database, there seems to be a connectivity issue

Attempting to set up a JWT authentication system using NestJs and SQLite. The code successfully generates the SQLite file, but then throws an error stating "Unable to connect to the database." Upon checking with the SQLite terminal, it became apparent that ...

Using relative URLs in Angular 2 CSS

Struggling in Angular 2 to set a background image for a division using a .css file in the component, but encountering errors due to relative paths. test.component.html <div class="release-bg"></div> test.component.css .release-bg{ b ...

Upon running the code, no errors appear on the console. However, my project isn't functioning properly and I'm encountering errors on the web console

ReferenceError: require is not defined when trying to access external "url" at Object.url in webpack_require (bootstrap:83) at client:6 importing from webpack-dev-server client index.js(http://0.0.0.0:0) vendor.js:219506 dynamically imp ...

Disabling the submission button in the absence of any input or data

I am currently experiencing an issue where the submit button is active and displays an error message when clicked without any data. I would like to rectify this situation by disabling the submit button until there is valid data input. < ...

Passing a FormGroup from an Angular 2 component as a parameter

I have a FormGroup that contains a SubFormGroup: sub formGroup initialize: this.fg=new FormGroup({ name: new FormControl(), abcFg: new FormGroup({ aaa: new FormControl(), bbb: new FormControl() }) }) ...

Guard against an array that contains different data types

I am trying to create a guard that ensures each entry in an array of loaders, which can be either query or proxy, is in the "success" state. Here is my attempted solution: type LoadedQueryResult = Extract<UseQueryResult, { status: 'success' }& ...

Creating an Angular 2 project with DevExtreme in Visual Studio 2017/2015: A step-by-step guide

I would appreciate some guidance on setting up an Angular 2 project with DevExtreme control using Visual Studio 2017/2015. Specifically, I am interested in utilizing the control demonstrated at . Your assistance would be greatly appreciated. ...

I am attempting to update the URL of an iframe dynamically, but I am encountering an issue: the Error message stating that an Unsafe value is being

Currently, I am attempting to dynamically alter the src of an iframe using Angular 2. Here is what I have tried: HTML <iframe class="controls" width="580" height="780" src="{{controllerSrc}}" frameborder="0" allowfullscreen></iframe> COMPONE ...