[英]access value in array from Json response angular 4
i wanna display a field in array at table .. how can i access SubjectCode in my Json Response using angular 4 ? 我想在表的数组中显示一个字段..如何使用angular 4在Json Response中访问SubjectCode? .. My code give me error [Error trying to diff '[object Object]'.
..我的代码给我错误[尝试区分'[object Object]'时出错。 Only arrays and iterables are allowed]
只允许使用数组和可迭代项]
Json Response : 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: 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: Meeting.component.ts:
this.dataStorageService.getCouncilId(this.meetingID).subscribe(response => {
this.subjectsWithID = response.json();
console.log(this.subjectsWithID, 'all Json Resopnse Here')
});
You should use ngFor over subjects, code should be, 您应该对主题使用ngFor,代码应为,
<tr *ngFor="let subject of subjectsWithID.subjects">
<td > {{subject.subjectCode}} </td>
</tr>
Your subjects
property is an array. 您的
subjects
属性是一个数组。 If you want to display it, then you should do 如果要显示它,则应该
{{subject.subjects[0].subjectCode}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.