I have made a rootscope function with a attribute. it is getting some data from a the db.
I want to use this rootscope function in a controller and put the data what i get in a variable.
$rootScope.get_option = function(option_name){
$http.post("server/read.php",{'subject': "options", "args": option_name })
.success(function (response) {
console.log(response);
$rootScope.option_get_value = response;
});
if($rootScope.option_get_value){
return $rootScope.option_get_value;
}
}
And this i what i have in the controller
$scope.subscription.reduced_hourrate = $rootScope.get_option('verlaagd_tarief');
console.log($scope.subscription.reduced_hourrate);
When i run the script, i see in the logs $rootScope function giving me correct value back. But the scope is giving me undefined data back.
Why is this happening? and someone help me of give me some tips?