元素的FormArray中的Setvalue如何

时间:2019-04-27 10:58:55

标签: angular

我的表单数组名称为cake

cake: this.formBuilder.array([]),

Formarray cake是元素的

 initCake(c) {
    return this.formBuilder.group({
      cakeId: [c._id],
      codeId: [],
      cakelable: [c.cakeNumberLabel],
      cakeChecked: [],
      status: ['normal'],
      action: ['normal']
    });
  }

哪个输出:

0: {cakeId: "5bd3f638c77cfe5851828a28", codeId: null, cakelable: "1", cakeChecked: null, status: "normal", …}
1: {cakeId: "5bd3f638c77cfe5851828a29", codeId: null, cakelable: "2", cakeChecked: null, status: "normal", …}
2: {cakeId: "5bd3f638c77cfe5851828a2a", codeId: null, cakelable: "3", cakeChecked: null, status: "normal", …}
3: {cakeId: "5bd3f638c77cfe5851828a2b", codeId: null, cakelable: "4", cakeChecked: null, status: "normal", …}
4: {cakeId: "5bd3f638c77cfe5851828a2c", codeId: null, cakelable: "5", enter code here cakeChecked: null, status: "normal", …}
5: {cakeId: "5bd3f638c77cfe5851828a2d", codeId: null, cakelable: "6", cakeChecked: null, status: "normal", …}

我如何为每个元素数组设置值

示例4这样的索引codeId SetValue ...

1 个答案:

答案 0 :(得分:1)

.atarray上的at(index)方法:https://angular.io/api/forms/FormArray#at

该方法返回一个抽象控件,您可以在其中调用.setValue(value)。