I'm currently trying to read a Json array of objects from my Employees API, which is returning the following,
[
{
"Id": "00162c3a-2b70-4f50-80e8-6fee463cffdb",
"EmployeeNumber": 123,
"FirstName": "John",
"Surname": "Smith",
"JobTitle": "Developer",
"Email": "jsmith@company.co.uk",
"PhoneNumber": "89345 242397",
"ExtensionNumber": "2895",
"MobileNumber": "12343451234"
},
{
"Id": "048b73e7-a84d-439b-97c2-0c611a076eb0",
"EmployeeNumber": 125,
"FirstName": "Billy",
"Surname": "Smith",
"JobTitle": "Developer",
"Email": "bsmith@company.co.uk",
"PhoneNumber": "89345 242397",
"ExtensionNumber": "2896",
"MobileNumber": "12343451223"
}
]
In my AngularJs application I have a controller as follows,
'use strict';
app.controller('directoryController', ['$scope', 'Page', function ($scope, Page) {
Page.setTitle('Employee Directory');
$.ajax({
url: 'http://localhost:8080/SGIntranetService/api/employee/',
type: 'GET',
}).success(function (data) {
$scope.employees = data;
//console.log($scope.employees);
});
}]);
When returning to the console all of the objects appear to be there. Also to note, for some reason at the moment my Ajax call is making two requests to the Web API. (Not sure why this is)
Finally I am trying to use this in a partial view (ng-view), Only using one of the properties for testing until it starts working, then ill add the rest in.
<div class="container" ng-controller="directoryController">
<div ng-repeat="employee in employees">
<h3>{{employee.FirstName}}</h3>
</div>
On my index.html (master page) I have the following.
<div class="site-content">
<div class="content-header">
<div class="container" ng-controller="pageController">
<h1 class="page-title">{{Page.title()}}</h1>
</div>
</div>
<div class="container">
<div data-ng-view="">
</div>
</div>
</div>