I'm using anularJS in a project, I need a service in order to get JSONs with $http.get method, I think that a service would have an easier to read syntax:
app.service('ApiService' , function($http)
{
var self = this;
self.user = {};
self.user.getByName = function(){};
self.user.getByRate = function(){};
self.events = {};
self.events.getList = function(){};
self.events.getByDate = function(){};
return ({
user : self.user,
events : self.events
});
});
and then you can call it like:
$scope.reople = ApiService.use.getList('some url');
but from too many pages (like this and this and this) I've seen, seem it's more popular to use factory as a better approach. can you please explain me:
- why is factory preferred and more popular than service?
- which is more extendable and maintainable for a group work or for a developer working on an existing code?