【发布时间】:2018-04-20 21:48:21
【问题描述】:
我想在表格的数组中显示一个字段..如何使用 angular 4 在我的 Json 响应中访问 SubjectCode? .. 我的代码给了我错误 [Error trying to diff '[object Object]'。只允许使用数组和可迭代对象]
Json 响应:
{
"$id": "1",
"Council_ID": 88,
"place": "bla bla",
"number": "45",
"type": 1,
"date": "2017-11-08T00:00:00",
"time": "04:51",
"user_Id": 15,
"subjects": [
{
"$id": "2",
"subjectCode": "45",
"type": 1,
"faculty": "medicine",
"branch": "اسكندرية",
"gender": true
}
],
"absence": []
}
meeting.component.html:
<table class="table table-hover table-condensed text-center">
<tbody>
<tr *ngFor="let subject of subjectsWithID">
<td > {{subject.subjects.subjectCode}} </td>
</tr>
</tbody>
</table>
meeting.component.ts:
this.dataStorageService.getCouncilId(this.meetingID).subscribe(response => {
this.subjectsWithID = response.json();
console.log(this.subjectsWithID, 'all Json Resopnse Here')
});
【问题讨论】:
-
您的控制台日志显示什么?
-
它显示 json 响应 @tricheriche
-
您在对象而非数组上使用 *ngFor。你应该在你的 *ngFor 上使用
subjectsWithID.subjects -
是的,感谢您的帮助
标签: json angular http typescript