i have a function attached to angular app module through "app.factory" which has certain http requests in it. That function is invoked in the controller and the returned data from function is assigned to a scope variable in controller.
Problem is controller is being executed first and then the http requests in the function are executed due to which the data coming from http request can't be captured into scope variable. How that can be corrected.
function resourceapp.factory('dataService', function($http){
var data = {};
data.EnterprisePrograms = [];
data.Resources=[];
data.Skills=[];
data.Allocations=[];
Execution = function($http) {
$http.get('http://localhost:8080/api/enterpriseProgram')
.then(function(resources) {
data.EnterprisePrograms=resources.data;
});
$http.get('http://localhost:8080/api/resource')
.then(function(resources) {
data.Resources=resources.data;
});
$http.get('http://localhost:8080/api/skill')
.then(function(resources) {
data.Skills=resources.data;
});
$http.get('http://localhost:8080/api/allocation')
.then(function(allocation) {
data.Allocations = allocation.data;
});
}
return data;
});
controller
resourceapp.controller('AllocationList', function($scope, dataService) {
$scope.allocationList = dataService.Allocations;
});