2

I have been trying to make an http call for a while but I am stuck here as I am not able to resolve the actual data value from the returned $$state variable. This is my code:

function (action, req){
    var myData = $http.post('../rest/'+action, req)
        .then(function(response) {
           var data= response.data;
           console.log("data: "+data); //1st console
           return data;
        },
       function(response) {
          alert(JSON.stringify(response));
       });
   console.log(myData);   //2nd console
}

In the first console the values comes out to be fine as: data: This is my data.

However when I return the same value and print it in the second console it is wrapped up in a $$state object. This is my second console: d { $$state={...}, then=function(), catch=function(), more...}

When i expand it i get this value(in window>d): When I expand i get this:

Please help. What i need to do next to get $$state.value or d.$$state.value?

Vanellope
  • 55
  • 6
  • 1
    Probably that's dublicate of http://stackoverflow.com/questions/33843861/why-is-this-factory-returning-a-state-object-instead-of-response-data – Andriy Ivaneyko Dec 16 '15 at 08:19
  • I am not able to assign it to a global variable. This function is nested inside a function and is not directly inside a controller. I have tried assigning it to a global variable but for reason i don't know i am unable to do so. So I guess I need to parse this json to get the actual value. – Vanellope Dec 16 '15 at 09:15
  • In a number of places I have been reading that this is a promise returned and I need to resolve it in order to get the actual data. But I am not able to understand how to resolve it. Please help. – Vanellope Dec 16 '15 at 09:23
  • 1
    take a look at [$q](https://docs.angularjs.org/api/ng/service/$q), maybe it would be esier for you to work with that service. – Andriy Ivaneyko Dec 16 '15 at 09:27
  • Thanks. For now I used a callback function and it worked well. I am new to angularjs and still learning. Will definitely learn about $q and try this using $q. – Vanellope Dec 16 '15 at 09:49

0 Answers0