Skip to content

amowu/angular-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

angular-db

An AngularJS IndexedDB provider base on db.js.

Requirement

Installation

Add a <script> to your index.html:

<script src="db.js"></script>
<script src="angular-db.js"></script>

And add dbService as a dependency for your app:

angular.module('myApp', ['dbService']);

Usage

Config IndexedDB with dbProvider:

app.config(['dbProvider', function(dbProvider) {
  dbProvider.config({
    server: 'PREFIX_',
    version: 1,
    schema: {
      phones: {
        key: { keyPath: 'phoneId' }
      }
      // etc...
    }
  });
}]);

Use db service to CRUD:

app.controller('PhoneListCtrl', ['$scope', 'db', function($scope, db) {
  db('phones').getBatch(function(phones) {
  	$scope.phones = phones;
  });
}]);

app.controller('PhoneDetailCtrl', ['$scope', '$routeParams', 'db', 
function($scope, $routeParams, db) {
  db('phones').get('phoneId', parseInt($routeParams.phoneId), function(phones) {
    $scope.mainImageUrl = phones[0].images[0];
  });
}]);

Documentation

Adding items

db('objectStore').putBatch(array, onSuccess);

Querying all objects

db('objectStore').getBatch(onSuccess);

Getting a single object by ID

db('objectStore').get('keyPath', value, onSuccess);

About

An AngularJS IndexedDB provider base on db.js

Resources

Stars

Watchers

Forks

Packages

No packages published