ERROR: Form control named 'products' is missing a value accessor

Encountering an error in my project:

ERROR Error: No value accessor for form control with name: 'products'.

Incorporating an array of Products in Myform component is what I aim to achieve.

Tackling 2 issues:

  1. Upon clicking the Register button, the aforementioned error appears.
  2. Although my products array displays correctly in the table, it turns empty upon Registration. Referencing my source code.<

Here's the Html code snippet:

<form [formGroup]="Myform" (ngSubmit)="onaddMyForm()">
  <div class="contant">
    <div class="input-field col s4">
      <div class="input-field col s12">
        <select formControlName="client_id" id="client_id" materialize="material_select" [materializeSelectOptions]="client">
          <option value="" disabled selected>ClientName</option>
          <option *ngFor="let item of client" [value]="item.client_id">{{item.clientName}}</option>
        </select>
      </div>
      <br>
      <div class="row">
        <div class="input-field col s12">
          <label for="total">total:</label>
          <input formControlName="total" id="total" type="text" class="validate">
        </div>
      </div>
    </div>
  </div>
  <br>
  <table formControlName="products" align="center" class="table table-bordered table-hover">
    <thead>
      <tr style="color:black;">
        <th>Price</th>
        <th>Quantita</th>
        <th>Subtotale</th>
      </tr>
    </thead>
    <tbody>
      <tr [routerLink]="i" class="group" style="cursor: pointer" *ngFor="let item of products; let i=index">
        <td>{{item.Price}}</td>
        <td>{{item.Quantita}}</td>
        <td>{{item.Subtotale}}</td>
      </tr>
    </tbody>
  </table>
  <br>
  <hr>
  <br>
  <div id="add_homebox_button_container" class="row" style="float: right;">
    <button id="add_client_button" type="submit" class="btn waves-effect waves-light">
      Register
    </button>
  </div>
</form>

Delving into my ts code:

Exploring my constructors:

     constructor(
        private router: Router,
        private fb: FormBuilder,
        private ss: ws,

      ) {
// Formulating the formGroup
            this.Myform = new FormGroup({
              'client_id': new FormControl('', Validators.required),
              'products': this.fb.array([]),
              'total': new FormControl('', Validators.required)
            });
            }

//Initiating the function that posts My form Value in ws
              onaddMyForm() {
            this.loading = true;
            let newprod = new Product(
              this.Myform.value
            );
            console.log(newprod)// my array shows as empty in the console

            this.ss.prodcreate(newprod).subscribe(
              result => {
                if (result === true) {
                  Materialize.toast('Prod saved successfully', 4000);
                     } else {
                  this.loading = false;
                }
              },
              error => {
                this.loading = false;
              }
            );
          }

Seeking solutions to rectify the issue. Image showcasing the error:

https://i.sstatic.net/sogKA.png

Answer №1

So, I encountered a similar issue where the error message was "ERROR Error: No value accessor for form control with unspecified."

I dedicated 2 days to trying to resolve this issue, scouring complete Stackoverflow for solutions.

In the end, what finally worked for me was:

  • Finding all instances of ngModel in my code and adding a name attribute to each one.
  • If a name was already specified, adding "ngDefaultControl" to it.

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

Tips for assessing the prop that is being passed to a styled component with React and TypeScript

I am trying to apply a background color to a styled component div only if the state "active" is true. This is how I am currently attempting to do it: function Main() { const [active, setActive] = useState(false); return ( <ChildCompone ...

Successfully generated files, now patiently awaiting typecheck results... encountering an issue with importing SASS modules

Issue Encountering a problem where adding SASS variables to TypeScript files causes the browser tab with an open devserver to hang, displaying Files successfully emitted, waiting for typecheck results.... Trying to figure out what's causing this iss ...

Select information from an array and store it within an object

I want to extract all objects from an array and combine them into a single object. Here is the current array data: userData = [ {"key":"firstName","checked":true}, {"key":"lastName","checked":true ...

Type inference in TypeScript with transitivity

Consider this code snippet for illustration: function foo(t: "number"): number function foo(t: "string"): string function foo(t: "boolean"): boolean function foo(t: "number" | "string ...

Codeigniter form_validation: Utilizing parameters effectively

I'm currently working on setting up form_1 with form_validation in my CodeIgniter project. The data entered in form1 will be transferred to form_2, which also includes form_validation rules. Below is the controller code snippet: public function reg ...

Using Tokens for Authentication and Authorization in an Angular 4 Application Integrated with an ASP.Net Core API

My app needs to be developed using Angular4 and ASP.Net Core API, with the following requirements: Authentication and authorization will be based on JWT tokens. This application will be accessed by both internal users and external users. Internal users s ...

Interface circular dependency is a phenomenon where two or more interfaces

In my MongoDB setup, I have created an interface that defines a schema using mongoose as an ODM. import mongoose, { model, Schema, Model, Document } from "mongoose"; import { IUser } from "./user"; import { IPost } from "./posts&q ...

To dismiss the Div, simply click on any area outside of it. Leveraging the power of SVG, D3

I need a way to hide my div by clicking outside of it. My SVG has a background and a graph with nodes on top of that. I have a special node (circle) on the graph, clicking on which makes a box appear. To show the box, I use the following code: d3.select ...

In Angular 8, a communication service facilitates interaction between parents and children

Using a Sharing service, I am able to pass data from my app component to the router-outlet render component. While I have been successful in passing strings and other data, I am now looking for a way to retrieve data from an API and share it with a compone ...

Issue: State in React component remains unchangedDescription: A problem

I am currently working on implementing protected routes that are accessible only when a user is logged in. However, I am facing an issue with retrieving the loggedIn state in the ProtectedRoutes component. It always remains false, leading to a redirection ...

`quill-emoji : The emoji fails to render properly`

Attempting to integrate quill-emoji with ngx-quill, but struggling to display the emojis in the pop-up or once inserted. It seems like a CSS inclusion may be missing (not mentioned in the documentation on GitHub). Check out this StackBlitz showcasing the ...

Trouble with selectionChange event in mat-select component in Angular 13

I'm having trouble getting the selectionChange event to fire in my mat-select when the value is changed. html file <mat-select (selectionChange)="changeCategory()"> <mat-option *ngFor="let category of categ ...

Error in JSON format detected by Cloudinary in the live environment

For my upcoming project in Next.js, I have integrated a Cloudinary function to handle file uploads. Here is the code snippet: import { v2 as cloudinary, UploadApiResponse } from 'cloudinary' import dotenv from 'dotenv' dotenv.config() ...

Unable to locate the term "module"

I've been working on a TypeScript file that includes an exported function called sum: This script is meant to be run in Node.js. function sum(a:number):number{ return a; } module.exports.sum=sum; I'm encountering some issues and I'm not ...

The problem with Vue 3 loop iteration

I am facing an issue while attempting to loop through the data from the App.vue component by passing props to a child component. When I try to display the contents, I encounter an error in the v-for loop. Upon reviewing the code and error message, it see ...

The ES6 reduce method is not giving the expected result

In Image 1, the output you will see if you log the final array from Snippet 1. My goal is to transform my array to match the format shown in Image 2. I attempted using lodash's _.uniqBy() method [Snippet 2], but the logged output of the reduce varia ...

Why does Typescript attempt to match argument types with all function overloads?

Seeking assistance from a TypeScript expert to guide me in implementing monadic behavior. My goal is to develop basic monadic functions like map and flatMap for a data type that can have four distinct forms. I've encountered challenges making the Typ ...

Encountering an Error: ExpressionChangedAfterItHasBeenCheckedError, whilst conditionally modifying an attribute of

One interesting approach I'm using is to conditionally add title attributes to elements. Here's an example: <div #optionEl class="option-title" [attr.title]="isTitleTruncated(optionEl) ? option.title : null"> {{option.title}} </div& ...

Issue with hydration in Next.js while trying to access the persisted "token" variable in Zustand and triggering a loading spinner

Below is the code snippet from _app.tsx where components/pages are wrapped in a PageWrapper component that handles displaying a loading spinner. export default function App(props: MyAppProps) { const updateJWT = useJWTStore((state) => state.setJWT); ...

Adjustable Material UI Switch that reflects the value, yet remains changeable

I am facing a challenge with integrating a Material UI switch (using Typescript) to showcase a status value (active/inactive) on my edit page, and making it toggleable to change the status. I have been able to either display the value through the switch OR ...