Reputation: 51
Well today i have a new problem. I'm trying to take multiple arrays of this json.
[ { "_id" : "541200a79fb6706de9164063" , "index" : 0 , "guid" : "403d5692-0f07-40e6-84f5-32cdee137127" , "isActive" : true , "school" : "BOILICON" , "address" : "532 Everit Street, Williamson, Kentucky, 197" , "registered" : "Monday, March 24, 2014 4:46 AM" , "professor" : [ { "id" : 0 , "name" : { "first" : "Mclean" , "last" : "Robertson"} , "email" : "[email protected]" , "age" : 36 , "phone" : "+1 (946) 436-2567" , "coursePrice" : "$4,882.28" , "favoriteParadigm" : "funcional"} ]}
Well i tried to do it like this on the html code:
$<div ng-controller="studentsController">
<table>
<tr ng-repeat= "student in data.students">
<td>{{student.index}}</td>
<td>{{student.guid}}</td>
<td>{{student.isActive}}</td>
<td>{{student.school}}</td>
<td>{{student.address}}</td>
<td ng-repeat="prof in data.students.professor">
email: {{prof.email}}
</td>
</tr>
</table>
</div>$
But it doesn't work for me. Can anyone help me please?
Upvotes: 0
Views: 1158
Reputation: 7666
Couple of things in the problem statement,
So your code will look like:
HTML:
<div ng-app>
<table ng-controller="test">
<tr ng-repeat="student in data.students track by $index">
<td>{{student.index}}</td>
<td>{{student.guid}}</td>
<td>{{student.isActive}}</td>
<td>{{student.school}}</td>
<td>{{student.address}}</td>
<td ng-repeat="prof in student.professor track by $index">email: {{prof.email}}</td>
</tr>
</table>
</div>
JS:
function test($scope) {
$scope.data = {};
var students = '[ { "_id" : "541200a79fb6706de9164063" , "index" : 0 , "guid" : "403d5692-0f07-40e6-84f5-32cdee137127" , "isActive" : true , "school" : "BOILICON" , "address" : "532 Everit Street, Williamson, Kentucky, 197" , "registered" : "Monday, March 24, 2014 4:46 AM" , "professor" : [ { "id" : 0 , "name" : { "first" : "Mclean" , "last" : "Robertson"} , "email" : "[email protected]" , "age" : 36 , "phone" : "+1 (946) 436-2567" , "coursePrice" : "$4,882.28" , "favoriteParadigm" : "funcional"} ]}]';
$scope.data.students = JSON.parse(students);
}
Upvotes: 0
Reputation: 20741
Change prof in data.students.professor
to prof in students.professor
since previously you have defined student in data.students
so that student
will contains professor
details internally
Try this out
<div ng-app='myApp' ng-controller="studentsController">
<table border="1">
<tr ng-repeat="student in students">
<td>{{student.index}}</td>
<td>{{student.guid}}</td>
<td>{{student.isActive}}</td>
<td>{{student.school}}</td>
<td>{{student.address}}</td>
<td ng-repeat="prof in student.professor">email: {{prof.email}}</td>
</tr>
</table>
</div>
Upvotes: 1
Reputation: 28548
within ng-repeat you have different scope and current item is directly accessible. So change
<td ng-repeat="prof in data.students.professor">
to this:
<td ng-repeat="prof in student.professor">
email: {{prof.email}}
</td>
Upvotes: 1