0

I have the following code, but I'm not sure how to add a success/error handler to the request.

$resource('/example.json', {}, {
  get_something:
    method: 'POST'
    url: '/example/get_something.json'
})

I thought I would be able to add success: or something similar here, but apparently that's not the case. How can I do something after this request is completed?

123
  • 8,733
  • 14
  • 57
  • 99
  • Use `.$promise.then`. You can refer this link : http://stackoverflow.com/questions/15531117/resource-callback-error-and-success – Vineet Agrawal Mar 14 '17 at 13:23

1 Answers1

0

You can handle the response (success/error/exception) as follows:

var example = $resource('/example.json', {}, {
    get_something: { 
       method: 'GET'
    }
});

var postParams = {}; // Define post params if any. If you have any post params just use example.get_something()
example.get_something(postParams)
    .$promise.then(function(response) {
        console.log(response);
    }, function(error) {
        console.log(error);
    })
    .catch(function(exception) {
        console.log(exception);
    });
Tessy Thomas
  • 1,475
  • 12
  • 19