What I want to do is have the $http call wrapped so I can use it as a function everywhere in my app without using it directly. Also, according to what I receive from the server I want to display a message, or other general things and separate the logic. My problem is I can't reach the data sent by the server. What am I doing wrong?
This is my service I wrapped the $http in:
Application.service('test', ['$http', function ($http)
{
this.test = function()
{
console.log('testttt');
}
this.fetchData = function(url, successCallback, errorCallback, parameters)
{
if (parameters)
{
$http.get(url, {params: parameters})
.success(function (data) {
successCallback();
})
.error(function (data) {
errorCallback();
})
.finally(function(data){
console.log(data);
});
}
else
{
$http.get(url)
.success(successCallback)
.error(errorCallback)
.finally(function(data) {
console.log('finally');
console.log(data);
if (data.message)
console.log(message);
});
}
}
}])
And the controller where I call it:
Application.controller('AccessLoggingController', ['$scope', '$http', 'initData', 'test', function($scope, $http, initData,test)
{
test.fetchData('/jewelry-room/move-user.action', function(){}, function(){}, {user:2000, task:7});
... etc more code