0

将默认值设置为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');
  }

有什么意见吗?

4

0 回答 0