angular-lfmo
v0.1.6
Published
Simple models for localforage.
Downloads
9
Maintainers
Readme
angular-lfmo
Angular factory to define simple models for https://github.com/mozilla/localForage (Offline storage, improved.)
Features:
Manages your model entries using an index
Allows you to find your models using filter expressions
Bind one entry or a collection to your
$scope
Lightweight (2.4kB) and depends on localForage only
Usage:
- Download the project or install via bower
bower install angular-lfmo
or npmnpm install angular-lfmo
- Download localForage or install via bower
bower install localforage
or npmnpm install localforage
- Put angular-lfmo.js and localforage.js into your project
- Add the module
angular-lfmo
to your application
angular.module('yourModule', ['angular-lfmo']);
- Use the
$lfmo
factory
angular.module('yourModule', ['angular-lfmo'])
.controller('yourCtrl', ['$scope', '$lfmo', function ($scope, $lfmo) {
var myModel = $lfmo.define('myModel');
myModel.bindAll($scope, 'items', {isActive: true});
myModel.create({name: 'foo', isActive: true})
.then(function (model) {
return myModel.update(model.id, {name: 'bar'});
});
myModel.create({name: 'john', isActive: false});
}]);
Visit this plunker for a complete example.
Factory Functions:
define(name)
: returns a model
Model Functions:
create(data)
: creates a new entryget(id)
: retrieves an entryupdate(id, data)
: updates an entry at given idremove(id)
: removes an entryfindAll(filterExpression)
: finds all entries matching the given filter expressionbindAll($scope, scopeKey, filterExpression)
: lets you directly bind all entries matching the given filter expression to a $scope variablebindOne($scope, scopeKey, id)
: lets you directly bind an entry to a $scope variable