I have a requirement where I want to retrieve a JSON object from the server. Below are two versions which do not work -
Version 1
app.service("authorization", ['$http', function($http){
var authMap = [];
$http.get('/authmap').success(function(data){this.authMap = data});
}]);
Version 2
app.service("authorization", ['$http', function($http){
var authMap = [];
$http.get('/authmap').success(function(data){authMap = data});
var getAuthMap = function(){return authMap};
}]);
In version one I am injecting the service into my controller and accessing it as authorization.authMap, it returns an empty [].
In version two, I am accessing it as authorization.getAuthMap(). Here it gives me an error that no such method is defined on the object ?
What is wrong with both the methods ?