I'm trying to get a link on a page to basically load a block of data from a database, then perform a function on that data. The method that gathers the data from the database works (I can see it if I step through in the browser after clicking the link), the problem is that the method which is meant to then process the data sees it as 'undefined'...it seems like a scoping thing to me, but I'm not sure what I'm doing wrong. Currently I just have a console log message inside the processData method, until I can resolve this issue. Here is the HTML for the link:
<div ng-show="Base" >
<a data-toggle="collapse" data-parent="Base" ng-click="processData(getDataFromDb('key101'))">Process Data</a>
</div>
And here are the controller methods (I didn't want to dump a ton of HTML in here, but further up I init the controller with ng-controller="dataProcessor"):
angular.module('baseApp').controller('dataProcessor', function($scope, $http) {
$scope.getDataFromDb = function(key) {
$http.get('/trm/get_data_from_database?key='+key).then(function(response) {
return response.data.block;
}, function errorCallback(response) {
console.log('Failed')
});
};
$scope.processData = function(data) {
console.log(data);
}
});
The end result is that when the link is clicked, getDataFromDb is called and the data is pulled from the database, that part works, it's just that when processData is called with the return from getDataFromDb as its arg, when I set a breakpoint and look at the 'data' arg in processData, it's 'undefined'.
Does anyone know what I'm doing wrong? Thanks!