純粋なjson文字列であるrepo-detailをテーブルに表示するために、angular2-seed(https://github.com/angular/angular2-seed)をテストします。次のコードをrepo-detail.component.htmlに追加してください。angular2:階層型Jsonデータが正しく表示されない
<table>
<tr>
<td>{{repoDetails.id}}</td>
<td>{{repoDetails.owner.login}}</td> <!--It's ok without this line-->
</tr>
</table>
データが正しく表示されません。コンソールでは、私が得た:
zone.js:388 Unhandled Promise rejection: Error in ./RepoDetailComponent class RepoDetailComponent - inline template:7:12 caused by:
Cannot read property 'login' of undefined ; Zone: angular ; Task: Promise.then ; Value: ViewWrappedError {_nativeError: Error: Error in ./RepoDetailComponent class RepoDetailComponent - inline template:7:12 caused by: Ca…, originalError: TypeError: Cannot read property 'login' of undefined
at DebugAppView._View_RepoDetailComponent0.…, context: DebugContext} TypeError: Cannot read property 'login' of undefined
at DebugAppView._View_RepoDetailComponent0.detectChangesInternal (/AppModule/RepoDetailComponent/component.ngfactory.js:108:72)
at DebugAppView.AppView.detectChanges
...あなたはここで何をしているか
<table>
<tr *ngIf="repoDetails">
<td>{{repoDetails.id}}</td>
<td *ngIf="repoDetails.owner">{{repoDetails.owner.login}}</td> <!--It's ok without this line-->
</tr>
</table>
を追加
'repoDetails'オブジェクトに' owner'フィールドがないようです。これを確認できますか? – echonax
お返事ありがとうございます。その後、{{repoDetails?.owner?.login}}を使用して問題を解決しました。 – PiPiNaN