I am trying to make use of the async
pipe to display a table in Angular, but am getting the error: "...Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays."
My code:
<div *ngIf="studentList | async; else loading">
<table>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr *ngFor="let student of studentList">
<td>{{student.id}}</td>
<td>{{student.first_name}}</td>
<td>{{student.last_name}}</td>
</tr>
</table>
{{studentList | json}}
</div>
<ng-template #loading>
<div>Loading ...</div>
</ng-template>
The back-end is returning an Observable<Student[]>
If I replace the ngFor
with the below, it works but that means two HTTP.get
calls are made, which I don't want:
<tr *ngFor="let student of (studentList | async)">
Is there a way for me to reuse the value of studentList
from the ngIf
within the ngFor
, thus only making one request to my back-end?