首页 > 解决方案 > 单击链接时如何将数据库中的项目添加到列表中?

问题描述

这是接口:

  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'”

标签: javascriptangularmongodbtypescript

解决方案


推荐阅读