I want to know if it is possible to make a service call that uses $http so it returns data directly without returning a promise? I have tried to use the $q and defer without any luck.
Here is what I mean:
I have a service:
angular.module('myModule').factor('myService', ['$http', '$q',
function($http, $q) {
// Public API
return {
myServiceCall: function() {
return $http.get('/server/call');
},
}
]);
And this is how I would call it:
// My controller:
myService.myServiceCall().then(function(data) {
$scope.data = data;
});
I want to avoid that and instead wish to have:
$scope.data = myService.myServiceCall();
I want it to be fully resolved at that line, is it possible?
I have tried some combinations of $q, defer and 'then' methods but can't seem to get it right since the method returns immediately.
Aucun commentaire:
Enregistrer un commentaire