I have a file with the name app.js and there, I use many controllers for my web applications. My problem is I repeat many times the same code. For example this $http POST
$http({
method: 'POST',
url: urlProfile,
data: $.param($scope.ProfileForm),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'X-Token': '\UsernameToken Token="' + mycookie + '"',
}
}).success(function(data, status, headers, config) {
$scope.showProfiles();
$('#newProfile').modal('hide');
$scope.notifications(
$scope.title = 'Notificación',
$scope.body = 'Se ha creado un nuevo perfil',
$scope.icon = '/img/restore.png'
);
}).error(function(data, status, headers, config) {
alert('No se ha guardado el Perfil con el nombre: ' + profilename);
});
How can I use this method like Service o Factory in my controllers and only provide the params like URL or Method