首页 > 解决方案 > 推送记录到课堂

问题描述

我有一个定义如下的类:

export class Children {
  relationship: string;
  firstname: string;
  middlename: string;
  lastname: string;
  gender: string;
  dob: string;
  ssn: string;
  phone: string;
  email: string;
  address1: string;
  address2: string;
  city: string;
  state: string;
  zip: string;
  disabled: string;
}

我将其导入到我的 .ts 文件中。

另外,我已将其初始化如下:

public children: Children[]=[];

但是在尝试添加记录时,我收到错误 TypeError: undefined is not an object (evalating 'child.relationship = this.chrelationship')

这是我用来推送记录的代码:

SaveChildren(): void {
    
    let child: Children;
    child.relationship=this.chrelationship;
    child.firstname=this.chfirstname;
    child.lastname=this.chlastname;
    child.middlename=this.chmiddlename;
    child.gender=this.chgender;
    child.dob=this.chdob;
    child.ssn=this.chssn;
    child.phone=this.chphone;
    child.email=this.chemail;
    child.address1=this.chaddress;
    child.address2=this.chaddress2;
    child.city=this.chcity;
    child.state=this.chstate;
    child.zip=this.chzip;
    child.disabled=this.chdisabled;
    this.children.push(child);

    console.log(this.children)

  }

我无法弄清楚我做错了什么......

标签: angulartypescript

解决方案


推荐阅读