I have the following controller.
spaModule.controller("galleryController", function($http, $scope) {
var test;
$http.get("resources/php/gallery.php").success(function(response){
test = response;
});
console.log(test);
});
This controller sends a get request to a PHP file which returns some JSON containing the file names of all the images I have in a certain directory. I know I should probably be using a service for this, but I will only be using this information in one controller, so I'd rather just keep it contained in this controller.
I need to get the response data from inside the anonymous function into the scope of the controller so that I can create a gallery directive with the JSON data.
The code that I've added to this question was my attempt at doing this. I think my problem may be that the .success function has it's own scope, or possibly the $http object, so I'm within a "nested" scope. That is I need to get the JSON out of the scope of the anonymous function, into the scope of .success/$http, then from that scope out into the controller's scope. I'm unsure if this is my problem, or if it is how to accomplish this.
How do I get my response JSON to my controller's scope?