/* Service */
.factory('ServiceContainer', ['$resource', function($resource) {
var defaultParams = {
'page': 0,
'size': 8
};
return {
getResource: function (customParams) {
return $resource(
dataConfig.host + '/:resource_name/:id/:resource_detail_name',
$.extend(customParams, defaultParams),
{
save: { method: 'POST' },
update: { method: 'PUT' }
},
{
'stripTrailingSlashes': 'true'
}
);
}
};
}]);
/* Code in your controller */
$scope.delete = function (options) {
$scope.feedback.state = '';
$scope.feedback.message = '';
$scope.parameters.id = $scope.model.id;
ServiceContainer.getResource($scope.parameters).remove(
$scope.model,
function (data, header) {
if (typeof data.cause == "undefined") {
if (data.status > 400) {
$scope.failure(data, null, options); // HTTP STATUS CODE > 400... It counts as a success
} else {
$scope.success(data, header, null, options); // Success!!
}
} else {
$scope.failure(data, null, options); // HTTP STATUS CODE = 400... It counts as a success and it doesn't return status code (but it returns a cause of error)
}
},
function (response) {
$scope.failure(response, null, options); // HTTP STATUS CODE >= 500
}
);
};