获得承诺对象的角度
问题描述:
var requestOne = $http({
method: 'POST',
url: $rootScope.apisrvr + 'user/user_signin',
data: { username: $scope.user.username, password: $scope.user.password },
});
这个值是我的代码,当我写:console.log(requestOne);
我得到: that获得承诺对象的角度
我只想得到$$state/value/data/salt
。但是,当我尝试console.log(requestOne.$$state.value.data.salt);
时,我收到错误TypeError: Cannot read property 'data' of undefined
。我如何从这里获得salt
?
答
的requestOne
是承诺变量本身,实际得到的结果,你需要一个.then
调用添加到像这样的承诺结束:
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);
});
Upvoted以下正确的答案,但总的来说还记得[任何以'$$'开头的角度属性都是_ private_](http://*.com/questions/19338493/what-is-the-double-dollar-sign-used-for-in-angular)并且应该通过非私有方法访问。 –