Reputation:
$scope.mydata= [
{
"_id": "5fc9e4cc8acc",
"_rev": "1-deeb3c992677",
"contacts": [
{
"Name": "A",
"role": "Lead ",
"ID": "[email protected]",
"ID2": "[email protected]"
},
{
"Name": "B",
"role": "Lead ",
"ID": "[email protected]",
"ID2": "[email protected]"
},
{
"Name": "C",
"role": "Lead ",
"ID": "[email protected]",
"ID2": "[email protected]"
},
{
"Name": "D",
"role": "Lead ",
"ID": "[email protected]",
"ID2": "[email protected]"
}
],
"Profiles": [
{
"uid": "00",
"building": "GRAY",
"location": "Johannesburg",
"id": "bbb",
"_rev": "1-130d25d6cf4ecf0c2f2ed55c46b468cb",
"email": "",
"name": "zzz",
"role": "Lead ",
"office_phone": "112233"
},
{
"uid": "00",
"building": "GRAY",
"location": "Johannesburg",
"id": "bbb",
"_rev": "1-130d25d6cf4ecf0c2f2ed55c46b468cb",
"email": "",
"name": "zzz",
"role": "Lead ",
"office_phone": "112233"
}
{
"role": " Network"
},
],
"codename": "Random"
"List": [
"000-7890",
"000-78901",
"000-78902",
"000-78903",
"000-78904",
],
"Date": "1/7/2016",
"contact_Name": "yyy",
"role": "Submitter",
"sales_Stage": "",
"Country": "South Africa",
}
]
This is the $scope variable i have.In my template i have to display the details like name and role.But im using multiple ng-repeats.Im not sure which is the best way to access it.
Now i have to display the Name and role in "contacts" . How can i use ng-repeat to loop through it . If anyone knows please help. Thanks in advance.
Upvotes: 1
Views: 52
Reputation: 663
You will need nested ng-repeat because you need to collect information from two sub properties property i.e. contacts's role and name, Profiles's role and name which are property of myData so try this:
<div ng-repeat="data in myData">
<div ng-repeat="contact in data.contacts">
{{contact.Name}} & {{contact.role}}
</div>
<div ng-repeat="pro in data.Profiles">
{{pro.name}} & {{pro.role}}
</div>
</div>
Upvotes: 1
Reputation: 689
You can use;
<div ng-repeat="var in mydata.contacts">{{var.Name}} & {{var.role}}</div>
Hope it helps!
Upvotes: 2