Angular 6动态表单渲染

时间:2019-03-07 11:39:21

标签: angular angular6 angular-forms angular-formbuilder

我想构建一个从值列表中读取字段的表单:

<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);

  }

但是从浏览器中我得到了这个错误:

enter image description here

最后,在主模块中,我导入ReactiveFormsModule。 有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

最后,我已经解决了我的问题。 Chrome浏览器正在缓存以前的更改,因此我看不到正确的解决方法。

相关问题