Angular 表单控件中的表单数组声明
Angular Form Array declaration in formcontrol
我的项目中有一个表单,其中包含多个表单控件。但是其中一个名为“shopIds”的必须是数组。现在我想通过 shopIds 传递空数组。我怎样才能做到这一点?我在这里添加我的代码:
TS:
ngOnInit(): void {
this.formInit();
}
formInit = () => {
this.couponForm = new FormGroup({
couponCode: new FormControl(null, Validators.required),
quantity: new FormControl(null, Validators.required),
quantityPerUser: new FormControl(null, Validators.required),
description: new FormControl(null, Validators.required),
startDate: new FormControl(null, Validators.required),
endDate: new FormControl(null, Validators.required),
shopIds: new FormControl([]),
minimumAmount: new FormControl(null, Validators.required),
reductionPercent: new FormControl(null, Validators.required),
reductionAmount: new FormControl(null, Validators.required),
priority: new FormControl(1),
});
};
您可以使用shopIds: new FormArray([])
,
我的项目中有一个表单,其中包含多个表单控件。但是其中一个名为“shopIds”的必须是数组。现在我想通过 shopIds 传递空数组。我怎样才能做到这一点?我在这里添加我的代码:
TS:
ngOnInit(): void {
this.formInit();
}
formInit = () => {
this.couponForm = new FormGroup({
couponCode: new FormControl(null, Validators.required),
quantity: new FormControl(null, Validators.required),
quantityPerUser: new FormControl(null, Validators.required),
description: new FormControl(null, Validators.required),
startDate: new FormControl(null, Validators.required),
endDate: new FormControl(null, Validators.required),
shopIds: new FormControl([]),
minimumAmount: new FormControl(null, Validators.required),
reductionPercent: new FormControl(null, Validators.required),
reductionAmount: new FormControl(null, Validators.required),
priority: new FormControl(1),
});
};
您可以使用shopIds: new FormArray([])
,