Answer the question
In order to leave comments, you need to log in
How to properly organize code reuse when using $Resource?
To use the $resource service, a factory is used (taken from here: https://gist.github.com/djavier/8186812):
module.factory( 'Resource', [ '$resource', function( $resource ) {
return function( url, params, methods ) {
var defaults = {
update: { method: 'put', isArray: false },
create: { method: 'post' }
};
methods = angular.extend( defaults, methods );
var resource = $resource( url, params, methods );
resource.prototype.$save = function() {
if ( !this.id ) {
return this.$create();
}
else {
return this.$update();
}
};
return resource;
};
}]);
Resource.query(
function(resource){
$scope.items=resource;
},
function(resource){
msgBox.notify ("Ошибка получения данных");// msgBox сервис с контроллером и директивой
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question