AngularCollection
Description
AngularCollection is a collection module for AngularJS.
Installation
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 bower.json
"dependencies": ... "angular-collection": "0.x.x" ...
API
-
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;
Define new factory
app
Get collection instance
var todos = TodoCollection;
Add new records
_id
property will be generated and attached to each new record.
todos;todos;todos;
Get a single record
Get a record from the collection, specified by an id or by passing in a record.
var todo = todos;
Update a single record
If a record is already in the collection, its attributes will be merged.
todos;
Remove a record from the collection
todos;
Get a single record, spcified by index
todos;
Sort records as they are added to collection
Sort the collection by title descending each time you call add()
var todos = $collection; todos; // performs sort todos; // performs sort
Sort records on demand
Sorts the collection by title descending but only when sort() is called
var todos = $collection; todos; todos; todos; // performs sort
Options
You can pass a single parameter to getInstance
to specify additional options.
var todos = TodoCollection;
Currently the only options available are idAttribute
and comparator
.
var todos = TodoCollection;
Contributors:
License:
The MIT License