Reputation: 53
I have form array name cake
cake: this.formBuilder.array([]),
Formarray cake
is elements's
initCake(c) {
return this.formBuilder.group({
cakeId: [c._id],
codeId: [],
cakelable: [c.cakeNumberLabel],
cakeChecked: [],
status: ['normal'],
action: ['normal']
});
}
Which output:
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", …}
How I set value for each array of elements
Example 4 index codeId SetValue like that ...
Upvotes: 0
Views: 229
Reputation: 209
.at(index) method on a formarray: https://angular.io/api/forms/FormArray#at.
That method returns an abstract control where you can call .setValue(value) on.
Upvotes: 1