无法在http服务的成功功能中设置范围变量

时间:2021-08-08 19:43:47

I have a http service where im attempting to save the result to a scope variable, but the debugger keeps returning that the variable does not exist.

我有一个http服务,我试图将结果保存到范围变量,但调试器继续返回该变量不存在。

Here is the code.

这是代码。

...
$scope.valueList = [];
$scope.getValues = function() {
        $http({
            url: '/restservice/values/',
            method: 'POST',
            data: this.json_data,
            headers: {'Content-Type':'application/json'}
        }).success(function (data, status, headers, config){
            this.valueList = data;
        }).error(function (data, status, headers, config) {
            console.log("Failed"); 
        });
}
...

1 个解决方案

#1


5  

this.valueList = data;

Should be

应该

$scope.valueList = data;

Angular is still Javscript, so this context scope still apply. Also, this in this case does not equal $scope.

Angular仍然是Javscript,因此这个上下文范围仍然适用。此外,在这种情况下,这不等于$ scope。

#1


5  

this.valueList = data;

Should be

应该

$scope.valueList = data;

Angular is still Javscript, so this context scope still apply. Also, this in this case does not equal $scope.

Angular仍然是Javscript,因此这个上下文范围仍然适用。此外,在这种情况下,这不等于$ scope。