当我单击链接时,如何从db将项目添加到列表?

时间:2019-06-06 13:14:38

标签: javascript angular mongodb typescript

这是接口:

  export interface Doctor {
  lastName: string;
  firstName: string;
  format: string;
  inami: string;
  _id: string;
  brusafe: {
   login: string;
  };
  }



  export interface DoctorList {
  doctors: Array <{
  id: string;
  gp: boolean;
   }>;
  }

这是我的功能:

addNewDoctor(newDoctor: Doctor) {
console.log(newDoctor);
this.linkedDoctorShort.push({
  id: newDoctor._id,
  gp: false,
});
this.doctorLinked.push(newDoctor);
this.onSave();
}

这是HTML:

<div class="doctorlist">
<a (click)="addNewDoctor(newDoctor)">add</a>
<ul *ngFor="let doctor of doctorLinked; let d = index" >

<li> {{doctor.lastName}} {{linkedDoctorShort[d].gp}}<a 
(click)="setAsGP(ind,isGP)"><i class="material-icons">
    assignment_ind
    </i></a><a (click)="deleteDoctor(doctor.lastName)"> <i 
    class="material-icons">
    delete
    </i></a></li>
   </ul>
</div>

当我单击链接“添加”时,我试图在列表中添加医生,但提示“无法读取未定义的属性'_id'”

0 个答案:

没有答案