I have the following Angular code:
var application = angular.module('Application', []);
application.controller('ImageController', function ImageController($scope, $http) {
$http.get('api/images').
success(function (data, status, headers, config) {
$scope.images = data;
}).
error(function (data, status, headers, config) { });
$scope.vote = function (image) {
$http.post('api/images/{key}/vote', { key: image.Key }).
success(function (data, status, headers, config) {
}).
error(function (data, status, headers, config) {
});
};
});
How can I have controllers in different files when they share the same application? I suppose I should use define the controller differently that: application.controller('ImageController', ...
I think I should remove the $http part from the controller, right? I was reading about Angular Factories and Services but I am not sure which to use.
My interpretation of a factory is something that delivers services on request. At least that is how is usually used in, for example, C#.
But in my example, how should I remove the $http part to a service / factory?
And how to inject it in the Controller?