I am trying to iterate over an Array property of an object as below:
<p>
Editing Course : {{course?.name}}<br/>
Course Outward Par : {{course?.getOutwardPar('MEDAL')}}<br/>
Course Outward Yards : {{course?.getOutwardYards('MEDAL')}}
</p>
<div class="container">
<h1>Course Form</h1>
<form (ngSubmit)="onSubmit()" #heroForm="ngForm">
<div class="form-group">
<table>
<tr>
<td><label for="name">Name</label></td>
<td><input type="text" class="form-control" id="name" name="name" required
[(ngModel)]="course && course.name">
</td>
</tr>
<tr>
<input type="number" class="form-control" id="hole1" name="hole1" required
[(ngModel)]="course && course.holes[1].tees['MEDAL'].par">
</tr>
<!--
--- BROKEN HERE---
-->
<tr *ngFor="let hole of course?.holes">
<td>{{hole.name}}</td>
</tr>
</table>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
Everything prior to the *ngFor works as expected including the below so the property holes
of course
can surely be considered to be an array. No?
<input type="number" class="form-control" id="hole1" name="hole1" required
[(ngModel)]="course && course.holes[1].tees['MEDAL'].par">
The ngFor triggers the error:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
There is some dicusssion here https://github.com/angular/angular/issues/6392 on the subject. The post by robwormald suggests that the ? opertaor can be used in such cases.