如何在表内使用表单组和表单数组进行同时迭代?我不知道如何在模板中处理它

时间:2019-10-26 04:49:21

标签: angular angular7 angular-reactive-forms

这将是输出:

enter image description here

我不知道如何在模板中处理它

 rateCardForm = this.fb.group({
     package: this.fb.group({
         freeDays: this.fb.array([]),
         paidDays: this.fb.array([]),
     }),
 });

1 个答案:

答案 0 :(得分:0)

据我对您捕获的屏幕的了解:

rateCardForm = this.fb.group({
     package: this.fb.array([
      this.fb.group({
         freeDays: [null],
         paidDays: [null],
        })
     ]),
 });

用于将新项目添加到数组中:

Add(){
    var _package=FormArray>this.rateCardForm.controls.package;
       _package.push( 
          this.fb.group({
             freeDays: [null],
             paidDays: [null],
         })
       )
}

要删除:

Delete(index){
   var _package=<FormArray>this.rateCardForm.controls.package;
   if(_package.controls.length>1){
      _package.removeAt(index)
   }
}