My goal is to transfer data from a service to a controller using AngularJS. Below is the code I am using:
.controller('lista',function($scope,cetrams){
$scope.hola="This is it";
var test;
var testfn = function(){
test = 'Lala';
};
cetrams.success(function(data){
testfn();
test = data;
console.log('Inside service: '+test);
});
console.log('Inside controller: '+test);
})
Even though the service is functioning properly and the success function is being executed, I am unable to access the variable outside of that function within the controller's scope.