angularjs - how to use ng-repeat for array items in object which is inside other object in single ng-repeat -


having data as:

{     "obj1":{       "obj11":[        {           "name":"tim",         "roll_number":"45"      },      {           "name":"tom",         "roll_number":"20"      },      {           "name":"deny",         "roll_number":"42"      }     ],     "obj12":[        {           "name":"jim",         "roll_number":"43"      },      {           "name":"crook",         "roll_number":"46"      },      {           "name":"michael",         "roll_number":"48"      }     ]   } } 

having keys "obj11" , "obj12" , want ng-repeat specific block of html code items corresponding these specific keys inside obj1. repeated block contains 'name' , 'roll_number' corresponding each object in array.

<div ng-repeat="item in obj1['keyvalue']">   <p>{{item.name}}</p>   <p>{{item.roll_number}}</p> </div> 

if keyvalue 'obj11', output :

tim

45

tom

20

deny

42

assign keyvalue $scope variable, use without quotes:

ng-repeat="item in obj1[keyvalue]" 

js:

$scope.keyvalue = "obj12"; 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -