As usual I'm wondering if there is a better way to do:
(The code extends a angular service)
(function(window, angular, undefined) {
'use strict';
angular.module('api.base', ['restangular'])
.factory('Base', function(Restangular) {
return function(route){
var elements = Restangular.all(route);
return {
one : function (id) {
return Restangular.one(route, id).get();
},
all : function (id) {
return elements.getList();
},
store : function(data) {
return elements.post(data);
},
copy : function(original) {
return Restangular.copy(original);
}
}
}
})
})(window, angular);
(function(window, angular, undefined) {
'use strict';
angular.module('api.post', ['api.base'])
.factory('Post', function(Base) {
function ngPost() {
this.prop = ['publish','draft'];
this.myMethod = function(){}
};
return angular.extend(Base('post'), new ngPost());
})
})(window, angular);