ERROR: Unable to locate control without a specified name attribute

After researching this issue on various platforms, I have not found a solution that works for my specific case. The problem arises when loading a form template dynamically in an HTML file. Interestingly, the error only occurs when the teamName is set to "b" instead of "a".

Here is a snippet of the HTML:

<meta name="viewport" content="width=device-width, initial-scale=1">
<button mat-button class="close-icon" [mat-dialog-close]="true">
  <mat-icon>close</mat-icon>
</button><form [formGroup]="myFormGroup" (ngSubmit)="onSubmit()">
    <div *ngFor="let form_elem of formTemplate">
      <div *ngIf="form_elem.id === flag">
        <div [ngSwitch]="form_elem.type">
          <div *ngSwitchCase="'textBox'">{{form_elem.value}}
            <input type="text" formControlName="{{form_elem.label}}" />
          </div>
          <div *ngSwitchCase="'number'">{{form_elem.value}}
            <input type="number" formControlName="{{form_elem.label}}"/>
          </div>
          <div *ngSwitchCase="'select'">{{form_elem.value}}
            <select formControlName="{{form_elem.label}}">
              <option *ngFor="let opt of form_elem.options">
                {{opt}}
              </option>
            </select>
          </div>  
        </div>  
      </div>
    </div>
    <div style=" display: flex; justify-content: center;">
      <input type="submit" value="save"/>
      <button class="reset" type="reset" value="Reset">Reset</button>
    </div>
  </form>

This is how it's implemented in the TS File:

  ngOnInit() {
    console.log(this.data)
    
    let group={}
    this.teamService.currentData.subscribe(message => {this.teamName = message
      if(this.teamName == "a")
      { 
        this.flag = 1;
        form_template.forEach(input_template=>{
          group[input_template.label]=new FormControl('',Validators.required);  
        })
        this.myFormGroup = new FormGroup(group);
      }
      else if(this.teamName == "b")
      {
        this.flag = 2;
        form_template.forEach(input_template=>{
          group[input_template.label]=new FormControl('',Validators.required);  
        })
        this.myFormGroup = new FormGroup(group);
      }});
  }

This is what the form_template data structure looks like:

const form_template = [
  {
    "id":1,
    "type":"textBox",
    "value":"Name",
      "label":"Name"
  },
  {
    "id":1,
    "type":"select",
    "value":"xz", 
    "options":["Yes","No"], 
      "label"&:"xz"
  },
  {
    "id"1,
    "type":"textBox",
    "value"&:"college",
      "label":""college"
  }, 
  {
    "ida2,
    "tpe':'textBox"',
    "value'"music"',
      "lbel"'music"'
  },
  {
    "idæ2,
    "typ'""textbox"",
    "vae:iBook"",
      "laüel`:' book'"
  },
  {
    "i(ps',
    "type,'eselect'";
    "valu.':   fruit\"",
    "options ,'mango";
    "banana'", 
      "lalel-''环境""
  },
  {
    "id¨!2,
    "tys:,+'textbo}",
    "vagdd'tabc'",
      "laej'ehtäbcë'
  }
]
export default form_template;

Answer №1

Upon further investigation, I discovered a typo in my JSON file where I mistakenly wrote "la,bel" instead of "label". This slight error turned out to be the culprit behind the issue in my code.

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

Steps for styling the header of an Antd Collapse Panel

I'm attempting to modify the text color in the header of an ant panel. Below is the entire ant collapse component code: <Collapse accordion defaultActiveKey={defaultOpenPanel}> <StyledCollapsePanel key="tasksAssignedToMe" header={ ...

Switching over to Typescript: Sending mapped properties

I'm having trouble converting my React.JS script to TypeScript. I need assistance in creating a drop-down navigation bar on my website. Here's a snippet from my Header.tsx file: The error message Property 'onClick' does not exist on t ...

Having an Empty Schema: A Guide to Configuring @ApiProperty in NestJS

When I create @ApiProperty() in my Dto, it looks like this: export class UpdateMeassageDto { @ApiProperty() message: { hash: string; created_at: Date; updated_at: Date; } } However, the result turns out to be empty. Here's what it ...

Jest identifies active handles when executing synchronous scrypt operations in the crypto module of Node.js

During the execution of a unit test using the scryptSync function from the crypto package, I am encountering error messages and warnings that are unfamiliar to me. For instance, here is an example of a unit test I am running in Jest: it('Should match ...

Having trouble looping through an array in Angular 2?

I am currently using a FirebaseObjectObservable to retrieve the value of a property from my firebase database. The property can have multiple values, so I stored them in a local array variable. However, I ran into an issue while trying to iterate through ...

It is imperative that the 'Access-Control-Allow-Origin' header value in the response is not set to '*' when the request's credentials mode is 'include'

I am currently working on establishing a connection using socket.io between Angular and a Node.js Server Within Angular, I have set up a new socket by importing socket.io-client and connecting it as follows: import * as io from 'socket.io-client& ...

What is the best way to adjust the THREE.js view to match the size of the canvas

I am trying to implement dragging and dropping an element to the mouse position by synchronizing THREE.js space with the canvas size, where the coordinates {0,0} are located at the center of the screen. If my element has a width of 500px, dropping it at a ...

Mastering the utilization of bootstrap-select in TypeScript while ensuring "noImplicitAny" is set to true can be quite the challenge, especially when confronted with the issue of bootstrap-select/index

Hello, I am currently exploring Typescript and attempting to incorporate bootstrap-select into a project that requires "noImplicitAny": true. However, I am encountering an issue while trying to import BootstrapSelect from @types/bootstrap-select. The erro ...

Can we utilize typescript configuration files to abstract the import of a node module in a similar fashion to the 'paths' property?

Currently, I am developing private node modules that may undergo significant structural changes in the future. This could involve splitting existing code into multiple packages. If there are 100 files importing from a package that no longer holds the impo ...

Leveraging Angular4 for server-side rendering capabilities

Today, my system is quite extensive and was built using Node.js, Express, Mongoose, and Pug. I am eager to transition the system to utilize Angular4 instead of Pug. This change will allow me to take advantage of rendering views on both front and back ends ...

Creating a Typescript type for the react-intl component within a single file

Currently, I'm trying to incorporate the injectIntl component directly in the file instead of using the traditional export default injectIntl(Component). However, I am encountering difficulties when it comes to typing the component. This is a snippet ...

How to effectively implement form-control with mat-radio-group?

UPDATE: Check out my code on stackblitz I'm facing an issue with my form layout. The form control rows are overlapping with the radio button rows. I need help to resolve this problem. Here is a snippet of my code: <form [formGroup]="formGroup" (n ...

tslint: no use of namespace and module is permitted

I have recently acquired a legacy .ts file that I would like to update. Two warnings appear: 'namespace' and 'module' are disallowed and The internal 'module' syntax is deprecated, use the 'namespace' keyword ins ...

Display various items from a predefined list using Angular's *ngFor directive

Within my Angular project, I am managing a list of reports. This list is structured as an array with a base class to accommodate different types of reports. Even though the list is defined as type: ReturnReport, the individual items can vary between type: ...

Examining for a TypeError with Typescript and Jasmine

In my current project, I am faced with the challenge of writing unit tests in Typescript for an existing library that was originally written in plain JS. Most of our page logic is also written in plain JS. Some functions in this library throw exceptions if ...

how to send both the useState setter and object as props to a child component in React using TypeScript

Having an issue with passing useState setter and object (both together) to the child component. Successfully passed the object by spreading it like this {...object}, but unsure of the syntax to pass the setter along as well. Here's a code example: < ...

Unable to access any pages using the angular-cli http-server for deployment

When I run my project using 'ng serve', everything works fine. However, when I deploy it on a server using 'http-server ./dist', none of the pages can be accessed and an error message is displayed: host:~/morange/project$ http-server . ...

TypeScript compilation will still be successful even in the absence of a referenced file specified using require

Having both Project 1 and Project 2 in my workspace, I encountered an unusual issue after copying a file, specifically validators/index.ts, from Project 1 to Project 2. Surprisingly, TypeScript compilation went through successfully without showing any erro ...

Converting objects to arrays in Typescript: A step-by-step guide

Can anyone assist me in converting a string to a Typescript array? Any help would be greatly appreciated. Take a look at the following code snippet: private validateEmptyOption(): any { console.log("CHECKED") let isValid = true; this.currentF ...

data being released from variables in angular ionic

I am truly perplexed as to why the variables aren't holding their values. I've declared a variable user and initialized it with data from the userData() function. However, it appears as undefined when I log it within the constructor as well as ...