GithubHelp home page GithubHelp logo

angular-collection's Introduction

AngularCollection

Build Status

angular-collection.js

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

angular-collection's People

Contributors

0x-r4bbit avatar ajoslin avatar damrbaby avatar eric013 avatar failpunk avatar falsetto avatar jseppi avatar mkuklis avatar tomkuk avatar warnerandy avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.