An AngularJS IndexedDB provider base on db.js.
- db.js v0.8.0
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']);
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];
});
}]);
db('objectStore').putBatch(array, onSuccess);
db('objectStore').getBatch(onSuccess);
db('objectStore').get('keyPath', value, onSuccess);