I am building an application with AngularJS that communicates with an ASP.NET Web Api Server.
In the angular client i have couple of services that communicate with the server through the $http core service.
The problem is that i can't return actual results from the http request but only a promise.
Lets say that i have a service that returns an array of tickets (some resource of my application) from the server:
myService.getAll = function () {
var result = $http.get('/api/tickets').then(function (result) {
if (result.status !== 200)
return [];
return result.data;
}, function (err) {
return [];
});
};
What can i do if i want to explicitly return the data of the result (or an empty array on failure) from the service and not a promise?
Is there a way to wait for a response in Angular?
Thanks, Arik