如何从ngForm转换为模型

时间:2018-12-14 12:43:43

标签: data-conversion angular-forms angular7

您好,我在将ngForm转换为interface时遇到麻烦。它总是导致undefined object

提交事件

onSubmitClicked(data:NgForm):void{
   console.log("submit form:");  
   console.log(data);  //looks exactly like the interface
   var x:User=data.value; 
   var y=data.value as User;
   console.log(x);  //undefined
   console.log(y);  //undefined
   this.userservice.createClientAsync(x);

 }

模型

export interface User{
    id:number;
    name:string;
    age:number;
    cnp?:string;
    children?:number;
    isMarried?:boolean;
}

0 个答案:

没有答案