I am attempting to read a JSON file and populate a table with the values. I've experimented with
this.http.get('./data/file.json')
.map(response => response.json())
.subscribe(result => this.results =result,
function(error) { console.log("Error happened" + error)},
function() { console.log(this.results)});
as well as:
this.http.get("./data/file.json")
.map(response => { return <ITest[]>(<ITest[]>response.json())})
.subscribe(result => this.results =result,
function(error) { console.log("Error happened" + error)},
function() { console.log(this.results)});
However, I keep receiving undefined
in the console. The GET
request appears fine as the response is visible in the network view in the debugger. I'm unsure of what I might be missing.
The HTML structure is as follows:
<ng-container *ngFor='let stat of results;let i = index' [attr.data-index]="i">
<tr>
<td style="text-align:left!important;" class="table-row">{{stat.Name}}</td>
<td class="table-row"> </td>
<td class="table-row">{{stat.Age}} </td>
</tr>
<tr *ngFor="let subitem of stat.Intervals">
<td style="text-align:right!important;">{{subitem.StartDate}}</td>
<td>{{subitem.EndDate}}</td>
<td >{{subitem.Duration}}</td>
</tr>
</ng-container>