Please ensure that the form builder displays the product name outside of the input field as well

Is there a way to display 'product.name' on the actual webpage using formbuilder? While it's working fine for the input field, I want to show the text in the first td tag:

<table class="editPackagesGeneralTable" formArrayName="products">
  <tr><th class="first">Product / Gift</th><th>Description</th><th>Cost</th><th class="last">Quantity</th></tr>
  <tbody>
  <tr *ngFor="let product of myForm.controls.products.controls; let i=index" [formGroupName]="i"><td>{{product.name}}</td><td>{{product.description}}</td><td>{{product.unitCost}}</td><td><input type="hidden" formControlName="id" /><input type="text" formControlName="name" /></td></tr>
   </tbody>
 </table>

This is how I've written my TypeScript:

this.myForm = this.fBuilder.group({
          products: this.fBuilder.array([])
      });

      this.httpService.getExtrasList()
          .subscribe((res) => {
              this.items = res.json();
              console.log(res.json());

              this.items.forEach(element => {
                  (<FormArray>this.myForm.get('products')).push(this.fBuilder.group({
                      id: [element.id],
                      name: [element.name]
                  }));
              });

          });

Answer №1

When referring to the FormGroup instance as product.name, using {{product.controls.name.value}} should yield the desired result.

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

Why is TypeScript resorting to using 'any' for specific prop type definitions in React?

Having some trouble with my props typing: export interface ITouchable { isDisabled?: boolean; margin?: Margin; height?: number; bgColor?: string; } The definition of Margin is as follows: type Margin = | { top?: number; bottom?: nu ...

How can I display an error message if the checkbox is not selected upon form submission?

If none of the checkboxes are selected, an error message should be displayed. The error message should be hidden when a checkbox is checked, but it's currently visible initially and disappears when unchecked. I would greatly appreciate your help. Than ...

Implement a function in a prototype that can be accessed globally, regardless of the module it is contained in

Trying to extend the functionality of the Array prototype in Typescript (1.8) through a module. The modification to the prototype is being made in utils.ts file: declare global { interface Array<T> { remove(obj: any): void; } } Arr ...

Enable scrolling exclusively for the content within a tab, without affecting the tab label in Clarity Tabs

I have a tab with lengthy content in my project (check out the StackBlitz reference here). This causes the appearance of a scroll. https://i.sstatic.net/ZcNKM.png The corresponding code snippet is provided below: <div class="content-container&qu ...

The functionality of the igx grid inline feature is not compatible with custom columns

Currently, I am implementing inline editing in the ignite-ui-angular grid. However, I am facing an issue where all rows are highlighted when I select a row, and the save/cancel prompt panel appears in the wrong row. The example provided by ignite-UI work ...

"Debating Angular: Comparing the Use of Getters and Methods in

To prevent cluttering the *ngIf directive with logic directly in the template. <div *ngIf="a === 3 && b === 'foo'"></div> I typically create a custom method like this: public isOk(): boolean { return a === 3 & ...

Testing server sent events with Angular solely using Karma-Jasmine

I am currently developing a web application using Angular for the frontend and Python for the backend. My implementation involves utilizing server-sent events (SSE) to stream data from the server to the user interface. While everything is functioning prope ...

What is the proper way to create a generic class that can produce various output types while implementing a basic interface?

An abstract class is being created here to transform one type of object into another, with a simple interface comprising id:string and type:string. The intention behind the class definition is to emphasize that it will produce an assembly and during insta ...

Issue encountered with ng serve following the installation of npm angular/cli

As a novice in the realm of nodejs and angular, I recently embarked on my journey by installing node and setting up a successful node project. Encouraged by this progress, I proceeded to execute "npm install -g angular-cli" followed by creating a new cli ...

When using Angular, the onSelectionChange event is not triggered for angular mat-option components

I am working with a mat-form-field that includes both an input field and a mat-autocomplete feature with mat-options. The input field has a (blur) event triggered when it loses focus, while the mat-option has an (onSelectionChange) event triggered when an ...

How to use D3 to add arrow directions to an SVG path

Within my svg path lies the representation of a shuttle track used in manufacturing processes. Every shuttle on this track moves in a distinct direction, and I wanted the svg path to visually indicate these directions for easy reference. Initially, I tried ...

Having difficulty in dynamically loading an image from an API's URL in Angular

In the title, I mentioned that I am utilizing a free API to display cryptocurrency news for my practice project. Everything seems to be working fine except for displaying the images in card view. I will share my code here, so if you have any suggestions on ...

Exploring resources within a library in Angular

I need help accessing assets from a shared library within my nx workspace. Here is the structure: /apps -- my-app // ... /libs -- shared -- assets -- resources -- translation.json The shared lib has an alias defined as @my-company/s ...

Launching the Bootstrap 5 modal will cause the header and background to shift towards the right side

Currently, I am working with Angular 2 and Bootstrap 5 for the front-end of my project. I noticed that when I open a modal, the header and background shift to the right, covering the scrollbar. Upon closer inspection, I discovered that the HTML code trans ...

The Angular 6 test command using npm has encountered a failure

I've been encountering a disconnect error while attempting to run Angular test cases. With over 1500 test cases written, it appears that the sheer volume may be causing this issue. Is there a way to resolve the disconnect error when running such a lar ...

Angular FormGroup's setValue method fails to accept specified string value

I've run into a peculiar issue recently. I'm trying to assign a value to a form controller in Angular this.form.controls['WhateverKeyIS'].setValue('ABC'); The above code works fine, but when I try to set a different value thi ...

When using TypeScript and the redux toolkit, the createSlice function encountered an issue with assigning a value to the 'state' parameter of a function

Hey there, I'm encountering an issue with my estlint: Assignment to property of function parameter 'state'. eslintno-param-reassign It's pointing to this particular code snippet: state.sideisOpen = action.payload; interface Sid ...

Employ the VSTS node API to retrieve all commits within a specified branch

I have been utilizing the vsts-node-api with reasonable success. However, my goal is to retrieve all commits in a specific branch, as detailed in the REST API documentation located here. Unfortunately, the node api only allows for commit queries in a rep ...

Why am I receiving a peculiar type error with @types/jsonwebtoken version 7.2.1?

My current setup includes node v6.10.3, typescript v2.3.4, and jsonwebtoken v7.4.1. Everything was running smoothly until I decided to upgrade from @types/jsonwebtoken v7.2.0 to @types/jsonwebtoken v7.2.1. However, after this update, an error started poppi ...

Synchronized management of multiple streams using RxJS

In a scenario where we have two Observable objects, observable A and observable B, both emitting randomly without our knowing the frequency or pattern of emission. Assuming that when observable A emits a value, we would like to wait for observable B to e ...