I am posting with AngularJS http.post, putting the response.data into a scope within the successCallback function. console.log writes the scope data but I can't acces the scope data within another function.
Init calls the function for the request.
$scope.init = function(group_year_id,year)
{
accessScopeFunction();
foo();
};
This is the called function
function accessScopeFunction() {
$http({
method: 'POST',
url: 'http://localhost/sjb/public/admin/groups/assing/angular/get/databasename'
}).then(function successCallback(response) {
$scope.getDatabaseName = response.data.event_db;
console.log($scope.getDatabaseName);
}, function errorCallback(response) {
return 'Fault';
});
};
I would like to pass $scope.getDatabaseName to another function
function foo() {
$http({
method: 'POST',
url: 'http://localhost/sjb/',
data: {'databasename':$scope.getDatabaseName}
}).then(function successCallback(response) {
}, function errorCallback(response) {
});
};
I read a lot about promise, AngularJS documentation, etc but I can't find a proper solution which works for me.