将默认值设置为Angular 4中FormArray中Formcontrol中新添加的选项控件

时间:2018-05-17 16:38:57

标签: angular formarray

在Angular 4中的FormArray中的Formcontrol中将默认值设置为新添加的选项控件

createBarWithData(): FormGroup {
    let data = JSON.parse(sessionStorage.getItem("allItems"));
    let fb: FormGroup = new FormGroup({
      allItem1: new FormControl(),
      allItem2: new FormControl(),
      allItem3: new FormControl(),
      allItem4: new FormControl(),
    })
    fb.controls.allItem1.setValue(_.head(data), { onlySelf: true });
    return fb;
  }
addMore() {
    let self = this;
    self.allItemsKnown.push(self.createBarWithData());
  }
 get allItemsKnown(): FormArray {
    return <FormArray>this.customerForm.get('ItemsKnown');
  }

有什么意见吗?

0 个答案:

没有答案