I'm looking at Angular's generic factory for CRUD (which I am currently in preference of over using a service):
app.factory('dataFactory', ['$http', function ($http) {
var urlBase = '/odata/ContentTypes';
// The _object_ defined in the factory is returned to the caller, rather than as with a service,
// where the _function_ defined in the service is returned to the caller
var dataFactory = {};
dataFactory.getContentTypes = function () {
var contentTypes = $http.get(urlBase);
return contentTypes;
};
dataFactory.getContentType = function (id) {
return $http.get(urlBase + '/' + id);
};
dataFactory.insertContentType = function (contentType) {
return $http.post(urlBase, contentType);
};
dataFactory.updateContentType = function (contentType) {
return $http.put(urlBase + '/' + contentType.ID, contentType);
}
dataFactory.deleteContentType = function (id) {
return $http.delete(urlBase + '/' + id);
}
// to traverse navigation properties
//dataFactory.getUserFromContentTypeId = function (id) {
// return $http.get(urlBase + '/' + id + '/user');
//}
//dataFactory.getOrders = function (id) {
// return $http.get(urlBase + '/' + id + '/orders');
//};
return dataFactory;
}]);
For all my entities, this code will be roughly the same. Is it possible to inject the entity name (or corresponding RESTful path), and if so, can this be treated like a partial class, where if additional promises are required (such as traversing navigation properties), they can also be injected?
If this is possible to do with Angular, can someone post some examples?