Angular Pass Deferred Error From Service To Controller
In my angular app I have a controller. The controller has a method which calls an asynchronous function in a service called Service. This is the controller code: $scope.controller
Solution 1:
I would write the Service as:
serviceMethod: function(x, y){
return $http.post('save', {
id: x, type: b
}).success(function(data){
// do things Service related when call is successful
}).error(function(data, status){
// do things error related...
})
}
And then reference it in a controller like this:
Service.serviceMethod($scope.x, $scope.y).success(function(data){
// request succeeded, so do nothing
}).error(function(data, status){
// error occured, do whatever
});
This works like a charm... Here is docs
Post a Comment for "Angular Pass Deferred Error From Service To Controller"