#FormGroupName not found

7 messages · Page 1 of 1 (latest)

cloud tree
#

Hello! I'm not sure why I can't use FormGroupName...

  public form: FormGroup = new FormGroup({
    client: new FormGroup({
      fileLink: new FormControl(''),
      file: new FormControl(FileRef),
      type: new FormControl('CLIENT_INSTRUCTIONS')
    }),
    contractor: new FormGroup({
      fileLink: new FormControl(''),
      file: new FormControl(FileRef),
      type: new FormControl('CONTRACTOR_INSTRUCTIONS')
    }),
    rkas: new FormGroup({
      fileLink: new FormControl(''),
      file: new FormControl(FileRef),
      type: new FormControl('RKAS_INSTRUCTIONS')
    }),
  });

// HTML 
<div class="modal-body">
  <div class="work-details-full-width" [formGroup]="form">
    <div class="work-details-1-row">
      <div class="work-details-1-col">
        <label class="work-details-1-label">Klient</label>
// it can't find this client
        <div class="w-100" [formGroupName]="client">
          Lisa link või fail
          <input class="form-control w-100"
                 formControlName="clientInput"
                 [class.is-invalid]="hasErrors(form.get('clientInput'))">
          <instruction-files-section instructionFileType="clientInput"></instruction-files-section>
        </div>
      </div>
waxen marten
#

Have you imported the angular form module in your *.module.ts (or in your *component.ts if you are using standalone components) ?

cloud tree
#

Yes, i have it imported

waxen marten
#

Your form fields in your template do not match your FormGroup fields, i.e. you are doing form.get('clientInput') but that field is not in your form, only fileLink, file and type

viral sundial
#

Also, [formGroupName]="client" should be formGroupName="client". client is a string here, not a property of your component.

waxen marten
#

Also, your formGroup is not on a form element, just on a div. Not sure if that is even possible.

cloud tree
#

oh yes, without [] it works.
Thank you