$http returns the promise :
Return a promise
updateTodoDetail: function(postDetail){ return $http({ method: "POST", headers: {'Content-Type': 'application/x-www-form-urlencoded'}, url: post_url, data: $.param({detail: postDetail}) });
So you can do
ajaxService.updateTodoDetail(updated_details).success(function(result) { $scope.result = result
Alternatively, you can pass the success function to updateTodoDetail :
updateTodoDetail: function(postDetail, callback){ $http({ method: "POST", headers: {'Content-Type': 'application/x-www-form-urlencoded'}, url: post_url, data: $.param({detail: postDetail}) }) .success(callback);
So your controller has
ajaxService.updateTodoDetail(updated_details, function(result) { $scope.result = result
I would prefer the first option so that I can handle errors, etc., without passing these functions as well.
(NB: I have not tested the code above, so some modification may be required)
source share