I have the following table:
<div data-ng-app="myApp">
<div data-ng-controller="MyCtrl">
<form>
<table>
<tr>
<td><b>ID</b></td>
<td><b>Name</b></td>
<td><b>Surname</b></td>
<td><b>House</b></td>
<td><b>Address</b></td>
<td><b>Locality</b></td>
<td><b>Contact1</b></td>
<td><b>Contact2</b></td>
<td><b>Contact3</b></td>
<td><b>Reply</b></td>
</tr>
<tr><td></td></tr>
<tr ng-repeat="telesale in telesales">
<td>{{telesale.ID}}</td>
<td>{{telesale.Name}}</td>
<td>{{telesale.Surname}}</td>
<td>{{telesale.House}}</td>
<td>{{telesale.Address}}</td>
<td>{{telesale.Locality}}</td>
<td>{{telesale.Contact1}}</td>
<td>{{telesale.Contact2}}</td>
<td>{{telesale.Contact3}}</td>
<td>{{telesale.Reply}}</td>
</tr>
</table>
</form>
</div>
</div>
controller:
<script type="text/javascript">
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {
GetPersons();
function GetPersons() {
$http({
method: 'GET',
url: '/api/data'
}).
success(function (data) {
if (data != null || data != 'undefined') {
console.log(data);
$scope.telesales = data;
}
})
.error(function (error) {
$window.alert("Unable to retrieve people" + error.message);
});
}
} ]);
The data is being retrieved from an api controller which returns a list of 40 objects, however only the first object is being displayed in the table. Why could this be happening?
Screenshot of some of the data retrieved from the api (data crossed out for privacy)
It looks as if the second (and the rest of the objects) are being passed as localities which is an foreign key of another table
API Code:
public HttpResponseMessage GetPeople()
{
List<CommonLayer.Telesales> list = new BusinessLayer.Telesales().getUserSession(User.Identity.Name);
//List<CommonLayer.Localities> list = new BusinessLayer.Localities().getAllLocalities();
if (list.Count > 1)
{
return new HttpResponseMessage()
{
Content = new StringContent(JArray.FromObject(list).ToString(), Encoding.UTF8, "application/json")
};
}
else
{
return null;
}
}
Please see here http://plnkr.co/edit/fLb9VHrGNqMtouK3dMca?p=preview it's workig but you should tune up your api to get data in better format
function GetPersons() {
$http({
method: 'GET',
url: 'data.json'
}).
success(function (data) {
console.log(data)
if (data != null || data != 'undefined') {
console.log(data[0].Localities.Telesales);
$scope.telesales = data[0].Localities.Telesales;
}
})
.error(function (error) {
alert("Unable to retrieve people" + error.message);
});
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments