I recently started learning Angular 1, and I've encountered an issue with my code:
var app = angular.module("Football", []);
app.factory("competitions", ['$http', function($http) {
return $http.get("json/competitions.json")
.success(function(response) {
var data = {
response: response,
teams: []
};
for (var i = 0; i < response.length; i++) {
$http.get("json/teams.json")
.success(function(response2) {
data.teams.push(response2);
return data
})
.error(function(err) {
return err;
});
}
})
.error(function(err) {
return err;
});
}]);
app.controller('MainController', ['$scope', "competitions", function($scope, competitions) {
competitions.success(function(data) {
$scope.competitions = data;
});
}]);
I am attempting to transfer the data from the competitions factory to $scope.competitions in MainController. However, only the response is being passed to the controller, which I recognize as incorrect. I'm unsure of how to rectify this mistake. Can anyone offer some assistance?