js-data localforage example

Users

{{ user.id }}: {{ user.name }}

angular.module('localforage-example', ['js-data'])
  .factory('store', function () {
    var store = new JSData.DS();

    store.registerAdapter('localforage', new DSLocalForageAdapter(), { default: true });

    return store;
  })
  .factory('User', function (store) {
    return store.defineResource('user');
  })
  .controller('localforageCtrl', function ($scope, User) {
    var lfCtrl = this;

    User.findAll().then(function (users) {
      $scope.users = users;
    });

    User.bindAll({}, $scope, 'users');

    $scope.add = function (user) {
      return User.create(user).then(function (users) {
        lfCtrl.name = '';
      });
    };

    $scope.remove = function (user) {
      return User.destroy(user.id);
    };
  });

<div class="list-group">
  <div class="list-group-item" data-ng-repeat="user in users track by user.id">
    <div class="pull-right">
      <button class="btn btn-xs btn-danger" data-ng-click="remove(user)">
        Delete
      </button>
    </div>
    {{ user.id }}: {{ user.name }}
  </div>
  <div class="list-group-item">
    <form id="user-form" name="user-form" data-ng-submit="add({ name: lfCtrl.name })">

      <input class="form-control" type="text" data-ng-model="lfCtrl.name" id="name" name="name"
             placeholder="Enter a name and press enter"/>
      <input type="submit" class="hidden"/>
    </form>
  </div>
</div>