I am trying to display 3 columns.
- Line
- AwayTeam
- HomeTeam
I am able to display Line column properly on the page. But 2nd and 3rd column which are AwayTeam and HomeTeam are not being displayed.
Here is the code that I tried
x.component.ts
import {Component} from '@angular/core';
import {HttpClient} from '@angular/common/http'
import {forkJoin} from 'rxjs';
import {map} from 'rxjs/operators';
@Component({
selector: 'app-mlb-api',
templateUrl: './mlb-api.component.html',
styleUrls: ['./mlb-api.component.css']
})
export class MlbApiComponent {
loadedCharacter: {
homeTeamName:string,
awayTeamName:string,
line:string,
EventId:string,
visitorTeam:string,
homeTeam:string} = <{homeTeamName:string, awayTeamName:string, line:string, EventId:string, visitorTeam:string,homeTeam:string}>{};
allhomeTeamName;
allawayTeamName;
allline;
constructor(private http: HttpClient) {
}
ngOnInit() {
let character = this.http.get('https://sportsbook.draftkings.com/api/odds/v1/leagues/3/offers/gamelines.json')
.pipe(map((re: any) => re.events));
let characterHomeworld = this.http.get('https://www.fantasylabs.com/api/sportevents/3/2019_06_17');
forkJoin([character, characterHomeworld]).subscribe(([draftkingsResp, fantasylabsResp]) => {
//this.allNames = draftkingsResp.map(r => r.name);
//console.log(this.allNames);
this.allhomeTeamName = draftkingsResp.map(r => r.homeTeamName);
//console.log(this.allhomeTeamName);
this.allawayTeamName = draftkingsResp.map(r => r.awayTeamName);
//console.log(this.allawayTeamName);
//this.alllabel = draftkingsResp.map(r => r.offers).flat().map(o => o.label);
//console.log(this.alllabel);
this.allline = draftkingsResp.map(r=>r.offers).flat().map(r => r.outcomes).flat().map(o => o.line);
console.log(this.allline);
//this.allline will have 'undefined' as well
//if you want then you can filter
this.allline = this.allline.filter(l => !!l);
console.log(this.allline);
});
}}
x.component.html
<table class="table table-striped table-condensed table-hover">
<div class="container">
<div class="row">
<div class="col-xs-4">
<div class="table-responsive">
<table summary="This table shows how to create responsive tables using Bootstrap's default functionality" class="table table-bordered table-hover">
<thead>
<tr>
<th>Information</th>
<th>HomeTeam vs AwayTeam</th>
<th>Line</th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<div class="container">
<div class="row">
<ng-container *ngFor="let n of allhomeTeamName">
<tr><td>{{n}}</td></tr>
</ng-container>
</tbody>
<tbody>
<tr>
<div class="container">
<div class="row">
<ng-container *ngFor="let n of allawayTeamName">
<tr><td>{{n}}</td></tr>
</ng-container>
</tbody>
</div>
</div>
<tbody>
<tr>
<div class="container">
<div class="row">
<ng-container *ngFor="let n of allline">
<tr><td>{{n}}</td></tr>
</ng-container>
</tbody>
</div>
</div> -->
<h4>Draft Kings</h4>
<table class="table table-striped table-condensed table-hover">
<thead>
<tr>
<th class="line">Line <a ng-click="sort_by('line')"><i class="icon-sort"></i></a></th>
<th class="awayTeamName">awayTeamName <a ng-click="sort_by('awayTeamName')"><i class="icon-sort"></i></a></th>
<th class="field3">homeTeam <a ng-click="sort_by('HomeTeam')"><i class="icon-sort"></i></a></th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let data of allline | paginate: { itemsPerPage: 5, currentPage: p }; let i = index">
<tr ng-repeat="data in pagedItems[currentPage] | orderBy:sortingOrder:reverse">
<td>{{data }}</td>
<td>{{awayTeamName}}</td>
<td>{{line}} </td>
</tr>
</ng-container>
</tbody>
</table>
<pagination-controls (pageChange)="p = $event"></pagination-controls>
How can I display 2nd column which is awayTeam and 3rd column which is homeTeam ?