While developing my web application using AngularJS, I have always relied on controllers to handle HTTP requests. This approach has made things easier and clearer for me.
However, in order to improve the code structure and enhance the execution of my application, I decided to shift towards using services instead of controllers for handling web services.
I attempted to create the following service:
var app = angular.module('ofcservices', []);
app.factory('news', ['$http', function ($http) {
var news={};
news.getnews= function () {
return $http.get('http://int.footballclub.orange.com/ofc/news?offset=0&limit=5');
};
return news;
}]);
And here is how the controller looks like:
.controller('news', function($scope, ofcservices) {
$scope.news = ofcservices.getnews();
})
Does everything appear to be correct?