gpt4 book ai didi

angular - 如何将 FormGroup 对象绑定(bind)到 ModelClass 对象

转载 作者:太空狗 更新时间:2023-10-29 17:52:35 24 4
gpt4 key购买 nike

在按钮上单击我必须发布和发送学生对象, 所以请告诉我如何将 formGroup 对象绑定(bind)到 ModelClass 对象, 不想手动将数据一个一个地添加到变量中。 我必须以单一方式绑定(bind),而不是手动绑定(bind)。

这是我的 formGroup 对象

this.AMform = fb.group({ 

"Name": new FormControl("", [Validators.required, Validators.maxLength(10) ]),
"Code":new FormControl("", [Validators.required, Validators.maxLength(10) ]),
"Address": new FormControl("", [Validators.required, Validators.maxLength(10) ])

});

这是我的模型

class Student 
{
public Name: string="";
public Code: string="";
public Äddress: string="";

}

最佳答案

点击按钮你可以做以下事情:

onClick(){
let student = new Student();
student = this.AMform.value;
}

关于angular - 如何将 FormGroup 对象绑定(bind)到 ModelClass 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40084699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com