Error: Cannot find control with path: 'specs -> 2' FormArray checkbox list

rahularyansharma

stackblitz

I am using reactive forms and in my forms I have an array of string with which I bind my checkbox list.

When I a trying to mark the returned array items to be selected, In console I am able to see the error

Error message in console

.ts code as follow :

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormArray, Validators } from '@angular/forms';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  form: FormGroup;

  spec = ['site-1', 'site-2', 'site-4'];

  constructor(private fb: FormBuilder) {}

  ngOnInit() {
    this.form = this.fb.group({
      specs: this.fb.array(['site-1', 'site-2'].map(s => this.fb.control(true)))
    });
  }
}

and html code as follow :

<form [formGroup]="form">
  <div class="col-3">
    <div class="form-group">
      <b>Select Spec Rows</b>
    </div>

    <div class="form-group overflow" formArrayName="specs">
      <div *ngFor="let site of spec; let i = index">
        <input
          type="checkbox"
          [id]="i"
          [formControlName]="i"
          [value]="site"
          (change)="specRowCheck($event,option.id, false)"
        />
        <div [innerHTML]="site"></div>
      </div>
    </div>
  </div>
</form>

ERROR Error: Cannot find control with path: 'specs -> 2'

I checked other questions and its seems I am missing some form group in my html but I am not sure how to apply that

Chellappan வ

You are setting formControlName directive for missing formControl that's why you getting this error.Since you using spec array in ngFor it have 3 value, in class you have only two array of formControl.

You should have 3 formControl inorder to match with spec array.

Try this:

this.form = this.fb.group({
      specs: this.fb.array(this.spec.map(s => this.fb.control(true)))
 });

Forked Working Example

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular 2 Form "Cannot find control with path"

Angular 2 Reactive Forms: Cannot find control with path

Angular material stepper: Error: Cannot find control with name: 'formArray'

Angular2: Cannot find form control at index 1 at FormArray

Angular 5 FormArray > Cannot find control with path: 'fields -> 0 -> name'

ERROR Error: Cannot find control with path

Angular FormArray: Cannot find control with path

Angular Reactive Forms: Cannot find control with path:

Cannot find control with path 'myFormArray -> [index] -> myProperty

Error: Cannot find control with path: 'x ' angular 2

FormArray : Cannot find control with unspecified name attribute in angular6

Angular 7 and form arrays error of cannot find a control with path

Cannot find control with path: 'marketplace -> 1 -> marketplace'

Angular 8 and form arrays error cannot find control with path: index

Angular Deeply Nested Reactive Form: Cannot find control with path on nested FormArray

Form Array: Cannot find control with path: 'list -> description'

Nested Form Array Woes: ERROR Error: Cannot find control with path: 'questions -> 0 -> code'

Python Error "[errno 2] system cannot find the path specified"

Angular Form Array Cannot find control with path

Get the following error : Error: Cannot find control with path: 'budgetIncomes -> 0 -> '

Cannot find control with path: 'plans -> 0'

Angular Error As Cannot find control with path: '_OSkilss -> 0 -> Imageuploade'

ERROR Error: Cannot find control with path: Angular FormArray

Angular. FormArray. Cannot find control with path: 'jobs -> 0 -> name'

ERROR Error: Cannot find control with path: 'flights -> 3'

Building form from json with repeatable inputs: Cannot find control with path formArray

Angular formArray Cannot find control with path

Angular Error: Cannot find control with path 'instructions -> 1 ->action'

Get error: Cannot find control with path: 'excludedPeriods -> 0 -> dateTo'

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive