Can I create more than one FormGroup in a component

1.3k views Asked by At

I've created a component with 2 FormGroups

In component class:

//Forms for Create and Edit nodes
public formCreateCategoryInLevel : FormGroup;
public formCreateCategoryInSubLevel : FormGroup;

this.formCreateCategoryInLevel = this.formBuilder.group({
  "categoryNameInLevel":[null,[Validators.required, Validators.maxLength(80)]],
  "categoryDescriptionInLevel":[null,[Validators.required, Validators.maxLength(300)]],
});

this.formCreateCategoryInSubLevel = this.formBuilder.group({
  "categoryNameInSubLevel":[null,[Validators.required, Validators.maxLength(80)]],
  "categoryDescriptionInSubLevel":[null,[Validators.required, Validators.maxLength(300)]],
});

//My submit forms methods:
onSubmitCreateCategoryInLevel(){
   //...some code
}
onSubmitCreateCategoryInSubLevel(indexSelected_ofSubParent: number){
   //...some code
}

In template:

     <form [formGroup]="formCreateCategoryInLevel" 
           (ngSubmit)="onSubmitCreateCategoryInLevel()">
           ...
     </form>


     <form [formGroup]="formCreateCategoryInSubLevel"                
           (ngSubmit)="formCreateCategoryInSubLevel(1)">
           ...
     </form>

The when I call the first form submit method onSubmitCreateCategoryInLevel(), everything works perfectly, but when I call the second method formCreateCategoryInSubLevel(1) i get an Exception enter image description here

As if one only one form can be created in a component, is this the case? or what?

0

There are 0 answers