This allows you to take advantage of the base class without having to re-write a bunch of CRUD code. Here is how you implement it.
Define a service: services/user.js
'use strict';
app.service('User', function User(Base) {
function UserService() {
this.ctrl = "user/";
}
UserService.prototype = new Base();
return new UserService();
});
app.service('User', function User(Base) {
var U;
function UserService() {
this.ctrl = "user/";
}
UserService.prototype = new Base();
U = new UserService();
U.setConfig({
api: "http://localhost:9000/",
cache: true
});
return U;
});
User.fill({name:"Bob"});
User.create().then(function(res){
// Created
});
User.all().then(function(res){
// All
});
Paginated object can be anything you want and will converted to a query string. For example: ?page=2&limit=4&per_page=4
User.all({page:2, limit:4, per_page: 4}).then(function(res){
// All
});
User.get(id).then(function(res){
// Get By Id
});
User.where({key:value,..}).then(function(res){
// Get By value pair
});
User.fill({name:"Carrie"});
User.update(id).then(function(res){
// Updated
});
User.delete(id).then(function(res){
// Deleted
});
bower install --save angular-base
<script src="path/to/bower/angular-base/base.js"></script>
angular.module('myApp', ['angularBase'])
$angularBaseConfigProvider.config({
api:"http://localhost:8081/",
cache:false
});
npm install
bower install
test
test-coverage
build