I have a Service in my angular app which gathers a JSON file with a football team's data.
angular.module('UsersApp').factory('SquadService', ['$http', function($http) {
return $http.get('squad/squad-bournemouth.json')
.success(function(data) {
return data;
})
.error(function(err) {
return err;
});
}]);
Is it possible to get the same service (SquadService) to return data from multiple JSON files?
Is this advisable?
If so, how would you make multiple
$http.get
functions in the same service? If not, would it just be a case of having a separate service for every squad array, and calling them all individually in the controller, like so...?bournemouthService.success(function(data) { $scope.bournemouthSquad = data; }); arsenalService.success(function(data) { $scope.arsenalSquad = data; }); chelseaService.success(function(data) { $scope.chelseaSquad = data; }); // and so on...
This seems like it goes against the DRY code principle, so wanted to know if there's a better way of doing this?
Thanks in advance