Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 访问angularjs中的私有$$状态变量_Javascript_Html_Angularjs_Http - Fatal编程技术网

Javascript 访问angularjs中的私有$$状态变量

Javascript 访问angularjs中的私有$$状态变量,javascript,html,angularjs,http,Javascript,Html,Angularjs,Http,我正在尝试通过http请求访问多个用户。 但所需的数据嵌套在私有$$状态变量中,我无法访问该变量 如果您得到的是$$state对象,则可能是在编写时直接访问从getMembers()函数返回的承诺。记住,承诺是异步的。要访问承诺中的数据,需要使用回调函数在承诺返回时访问数据 错误示例: response = getMembers(circleId); console.log(response); // the data is NOT in this response 正确的方法:

我正在尝试通过http请求访问多个用户。 但所需的数据嵌套在私有$$状态变量中,我无法访问该变量


如果您得到的是$$state对象,则可能是在编写时直接访问从
getMembers()
函数返回的承诺。记住,承诺是异步的。要访问承诺中的数据,需要使用回调函数在承诺返回时访问数据

错误示例:

response = getMembers(circleId);    
console.log(response); // the data is NOT in this response
正确的方法:

getMembers(circleId).then(function(response) {
    console.log(response);       // the data IS in this response
    $scope.data = response.data; // or something like that
});

如果您得到的是$$state对象,则可能是在编写时直接访问从
getMembers()
函数返回的承诺。记住,承诺是异步的。要访问承诺中的数据,需要使用回调函数在承诺返回时访问数据

错误示例:

response = getMembers(circleId);    
console.log(response); // the data is NOT in this response
正确的方法:

getMembers(circleId).then(function(response) {
    console.log(response);       // the data IS in this response
    $scope.data = response.data; // or something like that
});

演示如何调用
getMembers()
访问数据。注意使用
$q.defer()
是一种反模式,因为
$http
方法已经返回了一个promiseShow,告诉我们如何调用
getMembers()
来访问数据。注意使用
$q.defer()
是一种反模式,因为
$http
方法已经返回承诺