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

标签 angular

在按钮上单击我必须发布和发送学生对象, 所以请告诉我如何将 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/

相关文章:

angular - 扩展面板标题中的复选框

javascript - Angular 2.0 与 ui-router

ios - PWA 应用程序 - 使用 Angular 6 在本地存储中存储图像和视频

angular - 类变量仅在一种特定方法中未定义

Angular 7 - 收到错误 : 'rxjs has no exported member ' Observable'

Angular :ngrx 效果未触发

angular - 如何对组件类应用单一职责?

angular - 选中复选框时更改标签样式 - Ionic 3

javascript - 如何创建一个 Angular 分量的独立实例

angular - ngIf 带有 as as 语法和 && 运算符