Januka samaranyake Januka samaranyake - 2 months ago 16
AngularJS Question

ng-repeat with arrays

{
"employees" : [
{
"name" : "XXX",
"id" : "1",
"Salary" : [
{
"Month" : "XXXX",
"Amount" : "XXXX",
},
{
"Month" : "XXXX",
"Amount" : "XXXX",
},
{
"Month" : "XXXX",
"Amount" : "XXXX",
}
]
},
{
"name" : "YYY",
"id" : "2",
"Salary" : [
{
"Month" : "YYYY",
"Amount" : "YYYY",
},
{
"Month" : "YYYY",
"Amount" : "YYYY",
},
{
"Month" : "YYYY",
"Amount" : "YYYY",
}
]
}
],
}


I have this type of object. I assigned this into
vm.employess
variable in controller. Now I want to repeat this in the HTML area. I managed to do this:

<div ng-repeat="i in vm.employees">
{{i.id}}
{{i.name}}
</div>


I want to repeat salary as well but I was unable to do that. Can anyone help me on that!

Answer

As you've nested json, you need to use nested ng-repeat

<div ng-repeat="i in vm.employees">
            {{i.id}}
            {{i.name}}
    <div ng-repeat="sal in i.Salary">
         {{sal.Month}}
         {{sal.Amount}}
    </div>
</div>
Comments