我已经做了几乎所有的尝试,但是我一直在努力寻找检索数组的HTML。
我确实获得了球队名单,但是没有出现每个球队的球员(子代)。
应该像;
HTML
<h3>Registered teams</h3>
<ul>
<li *ngFor='let team of teams;let i = index'>{{ team.Name }} (id: {{ team.id }})
<ul>
<li *ngFor='let players of team.players;let j = index'>{{ player.Name }} ({{ players.id }})</li>
</ul>
</li>
</ul>
JSON
"id": 1,
"Name": "TEAM A",
"Active": true,
"created_at": "2019-09-12T13:56:52.045Z",
"updated_at": "2019-09-12T14:30:42.533Z",
"Players": [
{
"id": 1,
"Name": "PLAYER1",
"Active": null,
"created_at": "2019-09-12T13:56:41.496Z",
"updated_at": "2019-09-12T14:30:42.540Z"
},
{
"id": 2,
"Name": "PLAYER2",
"Active": true,
"created_at": "2019-09-12T14:00:12.149Z",
"updated_at": "2019-09-12T14:30:42.540Z"
}
model.ts
export class Team {
id: number;
name: string;
active: boolean;
players: {
id: number;
name: string;
}}
答案 0 :(得分:0)
您的json返回Players
,并且您引用了players
,并且您写了let players of team.players
。
应该是:
<li *ngFor='let players of team.Players;let j = index'>{{ players.Name }} ({{ players.id }})</li>