3

I am getting the error: TypeError: Cannot create property 'validator' on string 'control'"

import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { DataStorageService, FieldConfig, ImportType } from '../../../../services/datastorage.service';
import { ReactiveFormsModule, FormGroup, FormArray, FormControl } from '@angular/forms';


import * as Papa from 'papaparse';
@Component({
  selector: 'field-analysis',
  templateUrl: './field-analysis.component.html'
})

export class FieldAnalysisComponent implements OnInit {

  fieldsGroup;

  ngOnInit() {
    this.fieldsGroup = new FormGroup({ fieldset: new FormArray([new FormControl(''), new FormControl('')]) });

  }

}

And the template looks like this.

<h2 >Field Definition</h2>
<form formGroup="fieldsGroup" novalidate>


<input *ngFor="let control of fieldsGroup.controls['fieldset'].controls" formControl="control">
</form>

1 Answer 1

5

You passed string fieldsGroup to FormGroupDirective. You should pass FormGroup instance instead:

[formGroup]="fieldsGroup"

And FormControlDirective also expects FormControl instance

[formControl]="control"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.