Skip to content Skip to sidebar Skip to footer

How To Retrieve Data From Nested Json Object Using Ng-repeat

I'm trying to retrieve the EmpName from the below mentioned JSON object using ng-repeat. My js file: $scope.items = []; $scope.allItems = [{ 'categoryId': 1,

Solution 1:

YOu can do something like Every item contains Employee Array with only one Employee object. So you can get first item from Employee list and then get it's EmplyeeName

<divid="Div1"ng-repeat="item in items" ><divid="Div2" ><divid="Div3"><fontcolor="white">{{item.Employee[0].EmpName}}</font></div></div>

Solution 2:

According to the $scope.allItems array each item has a Employee property which is also an array:

{"categoryId":1,"categoryName":"abc","Employee":[{"EmpId":1,"EmpName":"Raj","EmpJob":"Accounts","DataList":[{"year":"Oct-2015","salary":"244"},{"year":"Jul-2015","salary":"100"},{"year":"Jun-2015","salary":"117"}]}]}

This property contains just one object which contains the EmpName property. Hence, to obtain the EmpName property, you'll need to access it via the first item of the Employee array:

<divid="Div1"ng-repeat="item in allItems"><divid="Div2" ><divid="Div3"><fontcolor="white">{{item.Employee[0].EmpName}}</font></div></div></div>

Post a Comment for "How To Retrieve Data From Nested Json Object Using Ng-repeat"