AngularCollection is a collection module for AngularJS.
angular-collection is a bower component you should be able to install it by running:
bower install angular-collection
or if you already have a bower based project you can add angular-collection to your dependency list in component.json
"dependencies": {
...
"angular-collection": "0.x.x"
...
}-
add(obj, options)
-
addAll(array, options)
-
sort()
-
get(obj | id)
-
update(obj)
-
remove(obj)
-
removeAll()
-
last()
-
at(index)
-
size()
-
all()
##Usage
####Specify dependencies
var app = angular.module('myApp', ['ngCollection']);####Define new factory
app.factory("TodoCollection", function($collection){
var TodoCollection = $collection();
return TodoCollection;
})####Get collection instance
var todos = TodoCollection.getInstance();####Add new records
_id property will be generated and attached to each new record.
todos.add({ title: "todo1" });
todos.add({ title: "todo2" });###Get a single record
Get a record from the collection, specified by an id or by passing in a record.
var todo = todos.get(10);####Update a single record
If a record is already in the collection, its attributes will be merged.
todos.update({ id: 1, title: 'todos3' });####Remove a record from the collection
todos.remove({ id: 1, title: 'todos3' });####Get a single record, spcified by index
todos.at(1);You can pass a single parameter to getInstance to specify additional options.
var todos = TodoCollection.getInstance(options);Currently the only options available are idAttribute and comparator.
var todos = TodoCollection.getInstance({idAttribute: 'id', comparator: '-created_at'});##Contributors:
##License:
The MIT License

