I have a simple json like this:
$scope.fruits = [
{
"type": "fruit",
"content": [
{
"name": "banana",
"type": "edible"
}
{
"name": "apple"
"type": "edible"
}
],
"id": 1
},
{
"type": "vegetable",
"content": [
{
"name": "eggplant",
"type": "edible"
},
{
"name": "poison ivy",
"type": "inedible"
}
],
"id": 2
}
]
I want my table to have this format:
<tr>
<td> fruit </td>
<td> 1 </td>
<td> banana </td>
<td> edible </td>
</tr>
<tr>
<td> fruit </td>
<td> 1 </td>
<td> apple </td>
<td> edible </td>
</tr>
<tr>
<td> vegetable </td>
<td> 2 </td>
<td> eggplant </td>
<td> edible </td>
</tr>
<tr>
<td> vegetable </td>
<td> 2 </td>
<td> poison ivy </td>
<td> inedible </td>
</tr>
However I can't seem to do this with ng-repeat because I can't nest loops, so something like this wont work:
<tr ng-repeat = "item in fruit in fruits">
<td> {{fruit.type}} </td>
<td> {{fruit.id}} </td>
<td> {{item.name}} </td>
<td> {{item.type}} </td>
</tr>
Should I somehow collapse my json so that there isn't nested arrays? or is there a way for angular to parse this? I've tried playing around with the filter functionality but with no avail. If someone could help me understand how I can achieve my intended results or point me in the right direction, I would very much appreciate it.