I want to read a json file and display the values in a table. I've tried
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)});
and this:
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)});
but I'm always getting undefined
in the console. The GET
response is ok, I can see the response in the network view in debugger. I don't know what I'm missing.
The html looks like:
<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>