How can I display elements from statusList2
within the statusList1
loop?
service.statusList1
contains two elements -> [0], [1]
service.statusList2
also contains two elements -> [0], [1]
<tr *ngFor="let status1 of service.statusList1; index as i">
<td>{{status1}}</td>
<td>{{service.statusList2[i]}}</td>
{{i+1}}
</tr>
I am utilizing Angular 6 for this task.
A more traditional JavaScript approach would look something like this:
for (let i = 0; i < someArray.length ; i++) {
let item = someArray[i];
}
However, I prefer a simpler Angular 6 equivalent using indexing in the loop like so:
<tr *ngFor="let status1 of service.statusList1; index as i">
<!-- <td>{{status1}}</td> -->
<td>{{service.statusList1[i]}}</td>
{{i+1}}
</tr>
To see an example, you can visit: https://stackblitz.com/edit/angular-1m31pe Feel free to make any edits or improvements on the example provided.