我创建了一个包含2个FormGroups的组件
在组件类中:
//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
}
在模板中:
<form [formGroup]="formCreateCategoryInLevel"
(ngSubmit)="onSubmitCreateCategoryInLevel()">
...
</form>
<form [formGroup]="formCreateCategoryInSubLevel"
(ngSubmit)="formCreateCategoryInSubLevel(1)">
...
</form>
当我调用第一个表单提交方法onSubmitCreateCategoryInLevel()时,一切正常,但是当我调用第二个方法formCreateCategoryInSubLevel(1)时,我得到一个例外
好像只能在一个组件中创建一个表单,是这种情况吗?或者什么?