Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

warnerandy/angular-collection

Open more actions menu
 
 

Repository files navigation

AngularCollection

Build Status

angular-collection.js

Description

AngularCollection is a collection module for AngularJS.

Instalation

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"
    ...
  }

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.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);

Options

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.