I'm really new with AngularJS and WebApi and I can't figure out how to wait for promises to be resolved.
I have a very simple application.
This is my HTML code:
<body ng-app="PersonApp">
<div ng-controller="PersonController">
<div id="personTable">
<table>
<tr ng-repeat="p in person">
<td>{{ p.surname }}</td>
<td>{{ p.name }}</td>
<td>{{ p.birthDate | date:'yyyy-MM-dd' }}</td>
<td>{{ p.fiscalCode }}</td>
<td>
<button type="submit" data-ng-click="edit(p)" class="btn btn-default">Edit</button>
<button type="submit" data-ng-click="delete(p)" class="btn btn-default">Delete</button>
</td>
</tr>
</table>
</div>//.................
My controller:
app.controller('PersonController', ['$scope', 'PersonApp', function ($scope, PersonApp) {
PersonApp.getPersons($scope);
And finally the service:
app.service('PersonApp', ['$http', function ($http) {
this.getPersons = function ($scope) {
return $http({
method: "GET",
url: "../api/person",
headers: { 'Content-Type': 'application/json' }
}).success(function (data) {
$scope.person = data;
console.log(data);
}).error(function (data) {
console.log(data);
});;
};
I have tried to insert promises everywhere but I really can't figure it out.
I know this is a really dumb question but I hope you have the patience to give me a simple aswer.
Many thanks in advance!