Guys is it possible to get the $http ajax functions of angularJS without being in a controller?
Currently i have got factories, where i would like to have to database manipulations:
var Services = angular.module('App.Services', []);
Services.factory('Data', function () {
var data;
return {
get:function (id) {
return merchants[id];
},
getAll:function () {
$http({method: 'GET', url: '/api/merchants'}).
success(function(data, status, headers, config) {
console.log(arguments);
}).
error(function(data, status, headers, config) {
console.log(arguments);
});
return data.slice(0);
},
add:function (_data) {
_data.id = data.length;
data.push(_data);
},
save:function (_data) {
merchants[_data.id] = _data;
},
remove:function (_data) {
delete merchants[_data.id];
}
}
});
How can i use $http now??