[英]Create a FormGroup Object via My Form inputs
I have created a Form called compaign
;我创建了一个名为compaign
的表单; My purpse is to register Form's inputs data within a FormGroup Object and send it to my backend !我的目的是在 FormGroup Object 中注册 Form 的输入数据并将其发送到我的后端! The first thing I have done it ;我做的第一件事; is that I created a FormGroup
model i used the class CompaignForms
, then i had to instanciate this class
using a local variable called compaignexample
;是我创建了一个FormGroup
model 我使用了 class CompaignForms
,然后我必须使用一个名为compaignexample
class
After that i have created the main FormGroup
object called compaignform
and i had to initialize it with compaignexample
attributes using get
method !之后,我创建了名为compaignform
的主要FormGroup
object ,我必须使用get
方法使用compaignexample
属性对其进行初始化! But the problem is in my template becauz i worked with formControl
and ngModel
at the beginning !但问题出在我的模板中,因为我一开始就使用formControl
和ngModel
! So i was urged to delete the directive [(ngModel)]
and i kept only formControlName
, However , the console displays that i have to make a parent component ( [formGroup]
) !所以我被敦促删除指令[(ngModel)]
并且我只保留了formControlName
,但是,控制台显示我必须创建一个父组件( [formGroup]
)! I tried it in vain !!我试了没用!! Please how can i fix that problem !请问我该如何解决这个问题! I mentionned my stackblitz demo and it doesnt contain the whole project !!我提到了我的 stackblitz 演示,它不包含整个项目! there is a path problem there !那里有路径问题! but the only problem which figure out currently is the one above !!但目前唯一能解决的问题是上面的那个!!
remove this code #compaignForm="ngForm"
from your form tag and add this [formGroup]="compaignexample"
to your form tag.从您的表单标签中删除此代码#compaignForm="ngForm"
并将此[formGroup]="compaignexample"
添加到您的表单标签。
<form [formGroup]="compaignexample" (ngSubmit)="saveCompaign()"></form>
ngForm
is used when creating Template-driven forms.创建模板驱动的ngForm
时使用 ngForm。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.