JavaCake
JavaCake

Reputation: 4115

Unable to set scope variable within success function of http service

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.

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"); 
        });
}
...

Upvotes: 0

Views: 775

Answers (1)

nowk
nowk

Reputation: 33191

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.

Upvotes: 5

Related Questions