J. Doe J. Doe - 3 months ago 18
Javascript Question

Access to value of promise object angular

var requestOne = $http({
method: 'POST',
url: $rootScope.apisrvr + 'user/user_signin',
data: { username: $scope.user.username, password: $scope.user.password },
});


This is my code, when I write:
console.log(requestOne);
I get:
that

I just want get
$$state / value / data / salt
. But when I try
console.log(requestOne.$$state.value.data.salt);
I get error
TypeError: Cannot read property 'data' of undefined
. How I can get
salt
from here?

Answer

The requestOne is the promise variable itself, to actually get the result, you need to add a .then call to the end of the promise like so:

var requestOne = $http({
                    method: 'POST',
                    url: $rootScope.apisrvr + 'user/user_signin',
                    data: { username: $scope.user.username, password: $scope.user.password },
                }).then(function(result){
                    console.log(result);
                });