Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  191] [ 2]  / answers: 1 / hits: 17243  / 7 Years ago, thu, march 2, 2017, 12:00:00

I am trying to display a table with values. Table has 5 columns, and in the 3rd column, I need value from another table. How can I implement this?



My html markup is:



list.component.html



<table >
<thead>
<tr>
<th> first </th>
<th> second </th>
<th> Third </th>
<th> Fourth </th>
<th> fifth </th>
</tr>
</thead>
<tbody>
<tr *ngFor=let item of items>

<td> {{item.name}}</td>
<td> {{item.subject}}</td>
<td *ngFor=let list of details>
{{list.firstName}}{{list.lastName}} ----> problem is here next 2 tds are not displaying the values properly
</td>
<td> {{item.fisrt}}</td>
<td> {{item.second}}</td>
</tr>
</tbody>
</table>


My item array



items[{name:, subject:, first:, second:}, {name:, subject:, first:, second:}]


My list array



  list[{firstName:abc, lastname:pqr}{firstName:abc, lastname:pqr}]


in the first two columns, the values are from one table, and the third column has a value from another table; the remaining two columns have the data from first table again.



How should I implement this?


More From » html

 Answers
129

I guess you require a nested table here in your case:



<tr *ngFor=let item of items>
<td> {{item.name}}</td>
<td> {{item.subject}}</td>
<td>
<table>
<tr>
<td *ngFor=let list of details>{{list.firstName}} {{list.lastName}}</td>
</tr>
</table>
</td>
<td> {{item.fisrt}}</td>
<td> {{item.second}}</td>
</tr>





I got the issue you are facing. i have created a demo @ plnkr.



The problem is you are having two objects in the items array so it loops two times for each object.


[#58709] Tuesday, February 28, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gideons

Total Points: 197
Total Questions: 106
Total Answers: 108

Location: Moldova
Member since Sat, Jan 29, 2022
2 Years ago
;