gpt4 book ai didi

angular - 从 formArray 中删除 FormControl

转载 作者:行者123 更新时间:2023-12-02 19:39:56 25 4
gpt4 key购买 nike

我创建了我的 FormGroup,如下所示

this.GSTNForm = this.formbuilder.group({
gstRegistrationStatusId: new FormControl(''),
reasonForNonApplicabilityofGST: new FormControl(''),
isExemptGoods: new FormControl(false),
goodServiceRemarks: new FormControl(''),
gstandbankDetails: this.formbuilder.array([
this.formbuilder.group({
_id: new FormControl(''),
sequenceNo: new FormControl(this.gstnSequenceValue),
gstn: new FormControl(''),
addressline1: new FormControl(''),
addressLine2: new FormControl(''),
stateCode: new FormControl(''),
cityCode: new FormControl(''),
countryCode: new FormControl(''),
pinCode: new FormControl(''),
accountHolderName: new FormControl(''),
accountTypeId: new FormControl(''),
bankName: new FormControl(''),
branchName: new FormControl(''),
bankCountryCode: new FormControl(''),
accountNo: new FormControl(''),
ifscCode: new FormControl(''),
micrCode: new FormControl(''),
swiftCode: new FormControl('')
})
])
});

我想删除 _id 表单控件,因为控件很复杂,我不知道如何删除。请帮忙。

最佳答案

这里的关键是浏览表单结构。到达 _id 所在的表单组后,您可以使用 removeControl('_id') 删除该控件。

const arr: FormArray = this.GSTNForm.get('gstandbankDetails') as FormArray;
const grp: FormGroup = arr.get('0') as FormGroup;
grp.removeControl('_id');

我为每个导航创建了一个步骤,但如果您愿意,您可以将其包装成一个巨大的调用。

我的偏好是将嵌套表单组存储为属性,然后您只需调用:

this.nestedGroup.removeControl('_id');

演示:https://stackblitz.com/edit/angular-vmtzaw

关于angular - 从 formArray 中删除 FormControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60412612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com