user1835326 user1835326 - 2 months ago 7
AngularJS Question

Angular Service Error not returning the control to then

I have a question regarding angular service. I have a controller and a service and if in service(which is calling a backend code) and I get an error. It is not transferring the control back to controller as if not returning a response.
How can I solve it

service call in controller

myservice.saveChange(data).then(function(data){
console.log(data);
//some Code
}


my service

this.myresp = function(obj){ $http.post(url,obj).success(function(data,status,headers,config){
this.resp = data;
}).error(function(data,status,headers,config){
this.resp = data;
})
return this.myresp;
}

M B M B
Answer

a promise takes in 2 callbacks a success and a fail . You can return your error from the second callback

$http.get('url').then(
    function(){return 'success';}, 
    function(){return 'error'});

Don't know if this can help you because you did not include any code