Angular Scaffold is a collection of convenience wrappers around angular-model collections.
npm install angular-scaffold




Angular Scaffold is a collection of convenience wrappers around angular-model collections.
Install the test runner with npm:
``bash`
npm install
You can then run the tests with Gulp:
`bash`
gulp
You can run coverage with:
`bash`
gulp coverage
See /docs/api.md in this project for detailed documentation of all angular-scaffold's functions.
Your API must:
* Use and interpret HTTP headers correctly (e.g. HTTP PUT, POST, GET and DELETE)
* Consume and return json
* Supply a $links collection containing a self key, e.g.:
`json`
[
{
"$links": {
"self": {
"href": "/api/posts/postaa"
}
},
"_id":"posta",
"name":"Post A",
"body":"Some content for Post A"
}
]
In your AngularJS application, include the JavaScript:
`html`
// your specific paths may vary
In your app configuration, state a dependency on Angular Model and Angular Scaffold:
`javascript`
angular.module('myApp', [
'ur.model',
'ur.scaffold'
]);
Example controller using Angular Scaffold:
`javascript`
.controller('PostsController', function($scope, scaffold) {
angular.extend($scope, {
posts: scaffold('Posts', {})
});
})
An example application is included in this repository. It has a very simple API that illustrates a basic use case for angular-scaffold.
To install and run the sample project:
`bash`
cd sample-project
npm install
node server.js
You can then browse to http://localhost:4730/ and add/remove Post objects from a list. angular-scaffold takes care of talking to the API for you.
angular-scaffold can paginate your model. Your API will need to support the Range: resources=n-n header to take advantage of this. For example, Range: resources=10-20 would return resources 10 through 20.
`javascript`
scaffold('Shares', {
paginate: { size: 20, page: 1, strategy: 'paged' }
});
You can pass a specific query in, which will be sent through to the API. Your API will have to know how to respond to this.
`javascript`
scaffold('Comments', {
query: {
offline: $scope.selected._id
}
});
You can also pass in an ordering parameter. Again, your API will have to know what to do with it.
`javascript``
return scaffold('Shares', {
query: { to: true, order: { _id: 'desc'} }
});