は、私は以下のようにオブジェクトの配列プロパティを反復処理しようとしています:エラー* ngFor
<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>
すべて前に*プロパティように、以下を含む、期待どおりに動作ngFor のcourse
は確実に配列とみなすことができます。いいえ?
<input type="number" class="form-control" id="hole1" name="hole1" required
[(ngModel)]="course && course.holes[1].tees['MEDAL'].par">
ngForはエラーをトリガ:
は型 'オブジェクト' が異なるサポート対象 '[Objectオブジェクトを]' が見つかりません。 NgForは、配列などのIterablesへのバインドのみをサポートしています。
ここにいくつかの相違があります。https://github.com/angular/angular/issues/6392 robwormaldの投稿は?そのような場合にはオペレータを使用することができます。
理由があるの? .holes –
@MiteshPant:非同期で受信されるデータの安全な演算子なので、データが到着する前にビューの読み込みにエラーがスローされることはありません:) – Alex
http://www.syntaxsuccess.com/viewarticle/ elvis-operator-in-angular-2.0 –