我想从值列表中构建一个读取字段的表单:
<form [formGroup]="fileForm" (ngSubmit)="onSubmit(fileForm.value)">
<section class="col col-8">
<div>
<label *ngFor="let metadato of metadatiAbilitati" class="input">
<input type="text" placeholder="{{metadato.chiave}}"
[formControl]="fileForm.get(metadato.chiave)" />
</label>
</div>
<!-- <label class="input">
<input type="file" name="file" placeholder="seleziona file" />
</label> -->
</section>
<!-- <div> -->
<button type="submit">Aggiungi</button>
<!-- </div> -->
</form>
在组件 ts 文件中,我有:
constructor(private transazioneService: TransazioneService, fb: FormBuilder) {
this.fileInputs = [];
let fields = {};
this.metadatiAbilitati.forEach(m => {
let input = this.fileForm.controls[`m.chiave`];
this.fileInputs.push(input);
fields[m.chiave] = m.chiave;
});
this.fileForm = fb.group(fields);
}
但是从浏览器我得到了这个错误:
最后,在主模块中我导入 ReactiveFormsModule。任何人都可以帮助我吗?