Ways to extract data from a Dynamic Form Element

I'm working on a form that allows me to dynamically create new input fields. You can check out my code at: CodeSandBox of My Code

My goal is to capture the value of each dynamically created input using formControl. Here is the code snippet:

HTML:

 (Code snippet for HTML)

TS:

 (Code snippet for TypeScript)

Is it possible to retrieve the values of the created input components using formControl? For example, if I have 2 inputs created:

Input 1: text01 <-- value Input 2: text02 <-- value

Answer №1

Uncertain about the desired outcome.

By utilizing this.validateForm.value, you have already accessed the values of your FormControls. Is that not sufficient?

By the way, considering a FormArray instead of a FormGroup would streamline your code.

Answer №2

 <form #uniqueForm="ngForm" ...otherparams>
   <fieldset *ngFor=".....">
    <div ngModelGroup="groupnamehere">
     //input and label with name and for
    </div>
   </fieldset>
 </form>

In the .ts file

@ViewChild('uniqueForm', null) form: NgForm

And then utilize this value to process the data as per requirement.

This functionality will generate an object with the ngModelGroup name serving as the object key upon submission.

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

Updating the state of the Store using NGRX

As I work on writing unit tests to evaluate the functionality of my NGRX store in Angular 10 with NGRX 10, I have been setting actions to manipulate the state as needed. Then, I run the test for the action and verify that it changes the state accordingly. ...

Create a function that is identical to the original, but omits the final

I am currently working on defining a type B that functions similarly to type A, but without the last parameter. I have attempted the solution below, however, it is still requiring 2 parameters instead of just one. type Callback = (msg: string) => void; ...

FIXED-IONIC 3: The 'questions' property is missing from the 'Object' type

Encountering an issue with a single line of code and exhausted all resources in attempts to resolve it. Seeking assistance for my simple quiz, disregarding the current data presentation. The trouble arises within my data.ts file, specifically at one parti ...

Exploring Typescript: A guide to iterating through a Nodelist of HTML elements and retrieving their values

I'm struggling to retrieve values from a Nodelist of input elements. Can anyone help me out? let subtitleElements = document.querySelectorAll( '.add-article__form-subtitle' ); ...

Having difficulty deploying a Node.js and Angular app on an Azure Web App via Azure DevOps

I am currently working on setting up a pipeline for my MEAN stack application in Azure DevOps. The frontend is developed using Node.js with Angular, while the backend is built with Node.js and Express. 1) Once I deploy the frontend Node.js project to an A ...

What factors should I consider when determining whether to include @types/* in the `dependencies` or `devDependencies` section?

Currently using TypeScript 2 in my project, I am looking to incorporate a JavaScript library along with its typings. While I know I can easily install the types using npm install @types/some-library, I am uncertain whether to use --save or --save-dev. The ...

Updating Angular 9 Reactive Form: How to Use PatchValue with a Nested FormArray in a FormGroup

I am currently working on maintaining an existing project that involves using a FormGroup helper to transform data into the FormGroup format. The FormGroup includes four nested FormArray elements, and my task is to update all the data within the FormGroup ...

Tips for sorting an array with various data types in TypeScript while explicitly defining the type

I need help with a class that contains two fields, each being an array of different types but sharing the common field id. I am trying to create a method that filters the array and removes an item based on the provided id. enum ItemType { VEGETABLES = &a ...

Exploring the Use of throwError in Angular 7 with RxJs 6.x

I'm having trouble using the second parameter (error) in my subscriber, it doesn't seem to be working properly. Here is the code for my Observable: return Observable.create(obs => { cognitoidentityserviceprovider.adminCreateUser(params, fu ...

Navigate to an Angular page URL using a Spring Boot REST API

I've been trying to figure out how to redirect to an Angular page from a Spring Boot API, but so far none of the methods I've tried have worked. Front end: (Angular) http://localhost:4200 Back end: (Spring Boot) http://localhost:80 ...

The submission of an Angular form results in errors such as being unavailable or

After building a registration page component in Angular and following tutorials, I encountered a frustrating bug. When pressing the submit button on the form, the console would display "undefined" when attempting to access the NgForm's value. However, ...

Can someone show me how to properly set up nested child routes in Angular 2?

My application structure is organized as shown below . ├── photos ├── posts ├── users │   ├── detail │   │   ├── address │   │   ├── family │   │   ├── information │   │   └ ...

What is the reason for typescript's lack of a "function" type?

As a newcomer to TypeScript, I'm puzzled as to why I am unable to define an object like this: const obj: { property1: string property2: boolean property3: function } It seems that the only workaround is to use: const obj: { property1: strin ...

Angular9: construction involves an additional compilation process

After updating my Angular8 project to Angular9, I noticed a new step in the build process which involves compiling to esm. This additional step has added approximately 1 minute to my build time. A snippet of what this step looks like: Compiling @angular/ ...

The correct assertion of types is not carried out during the initialization of generics through a constructor

I am encountering a minor issue with TypeScript, and I am uncertain whether it is due to a typo on my part or if TypeScript is unable to correctly infer the types. Let me provide all the necessary code to replicate the problem: interface IRawFoo { type: s ...

Designing a personalized Angular package for components

I am currently working on developing reusable components that can be utilized across multiple teams. After creating a new Angular project, I went ahead and published it to Azure DevOps artifacts. When attempting to use the component in another project, I ...

What is the best way to fetch the id of the option that has been chosen from a bootstrap drop-down menu?

I recently created a basic drop-down list like this: https://i.sstatic.net/4Tlxx.png Here is the HTML code for it: <select class="form-control" id='0' (change)="retrieveValue($event.target)"> <option id='0'>{{ g ...

How can you run a function in JavaScript or TypeScript that is stored as a string?

Is there a way to call a function that is stored as a string? For example: var dynamicFun = `function Hello(person) { return 'Hello' + person; }` In this case, the dynamicFun variable can store any function definition dynamically, such as: var ...

Unraveling the mystery of decoding a jwt token

Every time I attempt to validate a user token, I keep encountering Error 500. function verifyToken(req, res, next) { if(!req.headers.authorization){ return res.status(401).send('Unauthorized request') } let token = req.headers.authorization. ...

How can I access the component name and parameters during the NavigationEnd event?

We are currently setting up Google Analytics and we want to track the URL, parameters, and components in GA. this.router.events .pipe( filter(event => event instanceof NavigationEnd) ) .subscribe((event: NavigationEnd) => ...