I have array (gifts) of objects, after filled valid form by user, I want to check which checkboxes are checkIn, next push name of selected gifts into giftsArr and on submit-action push into gifts FormArray. I don't have idea how to do it.
gifts = [
{
text: 'Pack as a gift',
isClick: false,
},
{
text: 'Add postcard',
isClick: false,
},
{
text: 'Provide 2% discount to the next time',
isClick: false,
}
]
ngOnInit() {
this.signupForm = new FormGroup({
gifts: new FormArray([]),
});
onSubmit() {
const checkedGifts = this.gifts.filter((gift) => gift.isClick === true);
const giftsArr: any = [];
checkedGifts.forEach((gift) => giftsArr.push(gift.text));
// console.log(giftsArr) => ['Pack as a gift', 'Add postcard'];
}