In the example below I am trying to set a variable defined in the below service, in the success callback. I am unable to set the var authMap in the service. What is happening here and how do I do it?
app.service("authorization", ['$http', function($http){
this.authMap = [];
$http.get('/authmap').success(function(data){this.authMap = data});
}]);
A new scope is created in your anonymous callback function, so this
is different.
You could do something like:
app.service("authorization", ['$http', function($http){
this.authMap = [];
var that = this;
$http.get('/authmap').success(function(data){ that.authMap = data });
}]);