首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >很难使用Angular从API获取json数据。

很难使用Angular从API获取json数据。
EN

Stack Overflow用户
提问于 2019-06-12 02:48:20
回答 1查看 91关注 0票数 0

我正在尝试从https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json接口获取数据

并将它们存储在我的Angular应用程序的表中。我的页面上显示的是最初的15行,而不是所有行。并且我不能获取嵌套在object对象中的行数据。

这是我的HTML代码

代码语言:javascript
复制
  <div class="row">

<mat-toolbar color="primary">
  <span>Welcome!</span>
</mat-toolbar>


<div class="container">
  <br>
  <h2>Information</h2>  

    <span class="right"><a href="https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json" title="sportsbook1">API endpoint</a></span>     

   <table class="table  table-hover">
    <thead>
      <tr>
        <th>Id</th>
        <th>Name</th>
        <th>HomeTeamName</th>
        <th>AwayTeamName</th>
        <th>Start Date</th>
        <th>Offers</th>
        <th>Line</th>

        <!--<th>Image</th>-->
      </tr>
    </thead>
    <tbody>
      <ng-container *ngFor="let data of data.events">
      <tr>
        <td>{{data.id}}</td>
        <td>{{data.name }}</td>
        <td>{{data.homeTeamName }}</td>
        <td>{{data.awayTeamName}}</td>
        <td>{{data.startDate }}</td>
        <td>{{data.offers[1].label }}</td>
          <td>{{data.offers.outcomes[2].line }}        

        <!--<td><img class="image-width" src="{{contact.image}}" alt="{{contact.name}}}"></td>-->

      </tr>
    </ng-container>
    </tbody>
  </table>
</div>
</div>

这是我的打字代码

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
import { MatTableDataSource, MatSort } from '@angular/material';
import { DataSource } from '@angular/cdk/table';

@Component({
  selector: 'app-draftking',
  templateUrl: './draftking.component.html',
  styleUrls: ['./draftking.component.css']
})
export class DraftkingComponent implements OnInit {
 private apiUrl = 'https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json';
  displayedColumns = ['id','name', 'homeTeamName','awayTeamName','offers','line'];
  data: any = {};
  dataSource = this.data;

 constructor(private http: Http) {
  this.getLeague1();
  this.getData1();

 }


getData1(){
 return this.http.get(this.apiUrl)
  .map((res: Response) => res.json())
}

getLeague1() {
  this.getData1().subscribe(data => {
    console.log(data);
    this.data = data
  })
}
 ngOnInit() {
  }

}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56550037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档