我收到错误消息:TypeError:无法在字符串“ control”上创建属性“ validator””
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('')]) });
}
}
模板看起来像这样。
<h2 >Field Definition</h2>
<form formGroup="fieldsGroup" novalidate>
<input *ngFor="let control of fieldsGroup.controls['fieldset'].controls" formControl="control">
</form>
您已将字符串传递fieldsGroup
给FormGroupDirective。您应该FormGroup
改为传递实例:
[formGroup]="fieldsGroup"
而且FormControlDirective也希望FormControl
实例
[formControl]="control"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句