ngfor错误对象时出错

时间:2017-07-31 18:29:52

标签: json angular api angular-ng-if

在执行ngIf

时出错
<li *ngFor="let patient of patients">
        {{patient.id}}

    </li>

我的组件如下所示:

   private showAllPatients() {
   this.patientService.getAll().subscribe(patients => { this.patients = 
   patients; });

}

来自api的响应如下:

{
"patientProfiles": [
    {
        "id": "159",
        "firstName": "Anne",
        "lastName": "Frank"

    },
    {
        "id": "2",
        "firstName": "Max ",
        "lastName": "Start"  
    }]}

我认为这个问题是因为“patientProfiles”但是我怎样才能访问它?

1 个答案:

答案 0 :(得分:2)

您需要访问 patients.patientProfiles

<li *ngFor="let patient of patients.patientProfiles">