You can try the following method. This is a clean and manageable way to do this. You should have an AngularJS factory, which works as a service, which will delegate the controller class, where your contacts will be redirected to your own area of ββthe array. Then you can just loop it in the interface and you will get your contact. So here is the code:
Service
var module = angular.module('myApp', []);
module.factory('ContactService', ['$http', function($http) {
return {
getContacts: function(){
return $http.get("/PersonalDetail/AngularServlet").success(function(data){
return data;
})
}
};
});
controller
var module = angular.module('myApp', []);
module.controller('ContactController', ['$http', '$scope', 'ContactService', function($http, $scope, ContactService){
$scope.contacts = [];
ContactService.getContacts().success(function(data){
$scope.contacts.push(data);
})
}]);
index.html
<div data-ng-controller="ContactController">
<table class="table table-striped table-bordered" bgcolor="orange" border="1">
<thead>
<tr>
<th>Name </th>
<th>Email </th>
<th>Phone </th>
<th>Action </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contacts">
<td>{{ contact.name}}</td>
<td>{{ contact.email}}</td>
<td>{{ contact.phone}}</td>
</tr>
</tbody>
</table>
</div>
Hope this help :)
source
share