angular - 使用角度迭代数组 []
问题描述
当我调用 api 时,我有以下答案。
我有比这更多的属性,但我认为那更好
{
"id":1,
"FirstQuarter":[
{
"id":1,
"PLAYINFO":"Begin Period"
}
]
有角度的模型
export class Match {
id: number;
live: boolean;
teamA: String;
teamB: String;
codeTeamA: String;
codeTeamB: String;
actualQuarter: number;
header: Header;
FirstQuarter: FirstQuarter[];
}
export class FirstQuarter {
id: number;
}
这是我的组件:
export class PlayByPlayComponent implements OnInit {
match:Match;
constructor(private _playByPlayService:PlayByPlayService,
private route: ActivatedRoute,
private router: Router) { }
ngOnInit(): void {
var matchId = this.route.snapshot.paramMap.get('matchId');
this.getPlayByPlay(matchId);
}
getPlayByPlay(matchId:String){
this._playByPlayService.getPlayByPlaySyncronized(matchId).subscribe(
data=>{
this.match= JSON.parse(JSON.stringify(data));
},
(error)=>{
console.log("Error");
}
);
}
}
我有以下服务文件夹
@Injectable({
providedIn: 'root'
})
export class PlayByPlayService {
private basketball:string = environment.basketball;
constructor(private http: HttpClient) { }
getPlayByPlaySyncronized(matchId:String): Observable<any>{
return this.http.get(this.basketball+"/api/public/v1/match/"+matchId);
}
}
我正在用角度模板渲染结果,比如
{{match.id}}
{{match.gameCode}}
{{match.gameCode}}
{{match.TeamA}}
<table class="table table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let match of match.FirstQuarter">
<td>{{match.id}}</td>
</tr>
</tbody>
</table>
它像下面的图像一样打印,但我无法打印 firstQuarter
使用 console.log 的完整日志
解决方案
推荐阅读
- reactjs - 云图像不显示
- reactjs - React Firebase 根据时间戳值获取最新记录
- excel - 电源查询对小表发出数千次请求,刷新速度变慢
- android - 另一个应用程序的屏幕截图防护
- java - 根据java中的列名从excel中获取列值
- docusignapi - DocuSign - 为生产帐户切换帐户组
- c++ - 为什么物体的法线在相机移动时会改变颜色?
- angular - 在 Angular 9 e2e Protractor 测试中激活 Ng-ApiMock 模拟
- php - Laravel 会话过期错误修复未注销
- javascript - 使用服务进行http响应错误时如何访问“this”