Using AngularJS in my current project has been a smooth experience so far. One thing I have noticed is that when I loop over employees in my view, I have to use the code
<li ng-repeat="employee in employees.employee">
instead of just
<li ng-repeat="employee in employees">
This got me wondering why I can't directly access the employees to iterate through the different JSON objects.
Here are snippets of the code from my project:
Controller
Test.controller('EmployeeListController', function($scope, Employee) {
$scope.employees = Employee.query();
});
HTML View
<ul>
<li ng-repeat="employee in employees.employee">
<a href="mailto:{{employee.email}}" title="{{employee.email}}">{{employee.firstName}} {{employee.lastName}} ({{employee.email}})</a>
</li>
</ul>
Factory
Test.factory('Employee', function ($resource) {
return $resource('/TestServer/rest/employees/:employeeId', {}, {
update: {method:'PUT'},
query: {method:'GET', isArray:false}
});
});
JSON Response
{"employee":[{"created":null,"description":"TestDescription","email":"TestMail","firstName":"TestFirstName","id":"1","image":"TestImage.jpg","lastModification":null,"lastName":"TestLastName","phone":"121212121212"},{"created":null,"description":"TestDescription","email":"TestEmail","firstName":"TestFirstName","id":"2","image":"TestImage2.jpg","lastModification":null,"lastName":"TestLastName","phone":"2124343434"}]}