为什么我一直收到这个错误?我想我做的一切都正常吗?
“EXCEPTION:Uncaught(承诺):TypeError:value.forEach不是函数
TypeError:value.forEach不是FormArray.setValue中的函数“
组件类:
jobDetails: FormGroup; techFormArray: FormArray; constructor(private formBuilder: FormBuilder){ this.techFormArray = new FormArray([ new FormControl(''),new FormControl(''),new FormControl('') ]); this.jobDetails = this.formBuilder.group({ techs: this.formBuilder.array([]) }); this.jobDetails.setValue({ techs: this.techFormArray }); }
HTML:
<form [formGroup]="jobDetails"> <div formArrayName="techs" > <div style="display: flex; flex-direction: column"> <div *ngFor="let tech of techFormArray.controls; let i=index"> <md-checkBox [formControlName]="i"> {{i}} </md-checkBox> </div> </div> </div> </form>
解:
FunStuff没错,我无法使用setValue ….所以我删除了它.问题解决了哈哈.我改变了一些事情,我不确定我做了什么,它基本上是蛮力的试验和错误几个小时,但后来它工作了!