2

from angular contoller I calling http service

curServices = Cust_Serv.get(id);
console.log(curServices);

My service calls like this

get:function(data){
        var id= {'id':data};
        var promise = $http.post('api/admin/cust_serv/getserv',id).
            success(function(response){
            }).
            error(function(){
                console.log('no services found');
            });

        return promise;

    },

I receive response object with $$state, catch, error, finally, success, then, proto. I need only the values that is inside $$state->value->data.

How to access that data?

Dev Abel
  • 123
  • 1
  • 2
  • 12
  • 1
    `$http` service returns a `$q` - documentation for `$q` is here: https://docs.angularjs.org/api/ng/service/$q Best to get used to the docs vs asking people for the answers that are written in the docs. Also, `promises` can be tricky to newbies (or anybody really), so going through this documentation will be extremely helpful to you in the long run. – Adam Jenkins Nov 12 '14 at 15:35
  • Thank you Adam. I will look at $q. – Dev Abel Nov 12 '14 at 15:41
  • Use `.then()` with a callback. And no, you cannot directly access the value, because it's *not yet* available when you try. – Bergi Nov 12 '14 at 15:41
  • Thank you @Bergi that worked for get service's response. What if i used restful service and i used Customer.query() in angular. It returns data along with $promise and $resolve. How to get just data? – Dev Abel Nov 12 '14 at 16:15
  • Possible duplicate of [How to access the value of a promise?](https://stackoverflow.com/questions/29516390/how-to-access-the-value-of-a-promise) – Herohtar May 27 '19 at 03:59

1 Answers1

2

I followed as Bergi said and it worked.

Cust_Serv.get(id).then(function(response){
    curServices = response.data;
});
Dev Abel
  • 123
  • 1
  • 2
  • 12