-1

I'm creating a webapp with MEAN stack. In the backend, I have implemented an http get at: "http://localhost:8080/users/friends/" It works, because I have tried it with Postman and CURL. It returns an array of objects (it returns an array with all the elements of the collection "friends" in the server.

However, in the frontend I have a service with the following function:

this.getFriends = function() {
    var q = $q.defer();

    $http.get("http://localhost:8080/users/friends/")
        .then(
            function(friends) {
                q.resolve(friends);
            },
            function(err) {
                q.reject(err);
            }
        );

    return q.promise;
}

If I log it, it prints "object Object". The rest of the service is working.

11
  • does server method respond strigified json.. do console.log(friends) inside your $http.get success Commented Feb 20, 2016 at 17:57
  • check on the console what that object Object actually is. Commented Feb 20, 2016 at 17:58
  • Done. The result of the log in the server is the same array of objects. Commented Feb 20, 2016 at 18:02
  • I think Gandalf means for you to log the friends response on the client. Remeber, when getFriends() returns, you are getting a promise object. Commented Feb 20, 2016 at 18:06
  • Yep, I was anskering Pankaj Parkar. I've already done the log on the client and it just logs "object Object". How should I do the log to check what object Object actually is? Commented Feb 20, 2016 at 18:09

1 Answer 1

0

SOLVED: if you receive "data", to access the array you have to take "data.data", because the response is an object which contains the array.

Sign up to request clarification or add additional context in comments.

1 Comment

For more information on the response object, see AngularJS $http API Reference -- General Usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.