I am new to Angular 4 and I am stuck in an issue in my code. Below is my code:
JSON:
[{"name": "A", "date": "2017-01-01", "value": "103.57"},
{"name": "A", "date": "2017-01-08", "value": "132.17"},
{"name": "A", "date": "2017-01-15", "value": "268.04"},
{"name": "A", "date": "2017-01-22", "value": "235.10"},
{"name": "A", "date": "2017-01-29", "value": "83.78"},
{"name": "A", "date": "2017-02-12", "value": "162.52"},
{"name": "A", "date": "2017-02-19", "value": "131.63"},
{"name": "B", "date": "2017-01-01", "value": "0.56"},
{"name": "B", "date": "2017-01-08", "value": "275.55"},
{"name": "B", "date": "2017-01-15", "value": "288.37"},
{"name": "B", "date": "2017-01-29", "value": "250.05"},
{"name": "B", "date": "2017-02-05", "value": "124.90"},
{"name": "B", "date": "2017-02-12", "value": "6.15"},
{"name": "C", "date": "2017-01-08", "value": "75.55"},
{"name": "C", "date": "2017-01-15", "value": "88.37"},
{"name": "C", "date": "2017-01-22", "value": "34.31"},
{"name": "C", "date": "2017-01-29", "value": "0.05"},
{"name": "C", "date": "2017-02-05", "value": "4.90"},
{"name": "C", "date": "2017-02-12", "value": "6.15"},
{"name": "D", "date": "2017-01-08", "value": "5.55"},
{"name": "D", "date": "2017-01-15", "value": "8.37"},
{"name": "D", "date": "2017-01-22", "value": "4.31"},
{"name": "D", "date": "2017-01-29", "value": "50.05"},
{"name": "D", "date": "2017-02-05", "value": "4.90"},
{"name": "D", "date": "2017-02-12", "value": "6.15"}
HTML:
<thead>
<tr id="row">
<th class="align-right" *ngFor="let item of calendarTableSelected|slice:0:8">{{item.date}}</th>
</tr>
</thead>
<tbody id="body">
<tbody contenteditable='true'>
<tr class="align-right">
<ng-container *ngFor="let item of calendarTableSelected">
<td *ngIf="item.name == 'A'" [(ngModel)]="item.value" ngDefaultControl>
{{item.value}}
</td>
</ng-container>
</tr>
<tr class="align-right">
<ng-container *ngFor="let item of calendarTableSelected">
<td *ngIf="item.name == 'B'" [(ngModel)]="item.value" ngDefaultControl>
{{item.value}}
</td>
</ng-container>
</tr>
<tr class="align-right">
<ng-container *ngFor="let item of calendarTableSelected">
<td *ngIf="item.name == 'C'" [(ngModel)]="item.value" ngDefaultControl>
{{item.value}}
</td>
</ng-container>
</tr>
<tr class="align-right">
<ng-container *ngFor="let item of calendarTableSelected">
<td *ngIf="item.name == 'D'" [(ngModel)]="item.value" ngDefaultControl>
{{item.value}}
</td>
</ng-container>
</tr>
</tbody>
</table>
</div>
I do not want to hard-code the names: "A", "B", "C" and "D" in ngIf in HTML for the values to be displayed. Instead I want it to loop in the "name" field and display the value accordingly for that particular name.
I also do not want to change the json structure.
Please help.
Regards Neha