I am working with angularjs and chrome app. (Beginner in this scope) I am using idb library of promise for indexedDB. What I want is to get the all categories from store and return them in a controller function. my code look //check for support
if (!('indexedDB' in window)) {
console.log('This browser doesn\'t support IndexedDB');
}
const dbPromise = idb.open('test-db4', 2, function(upgradeDb) {
if (!upgradeDb.objectStoreNames.contains('category')) {
var category = upgradeDb.createObjectStore('category', {keyPath: 'cat_id', autoIncrement: true});
category.createIndex('cat_name', 'cat_name', {unique: true});
category.createIndex('cat_addedby', 'cat_addedby', {unique: false});
}
}
My Controller and factory Look like this
Factory :
app.factory('database', function(){
var factory = {};
factory.allCategories = function(){
val = [];
val = dbPromise.then(db => {
return db.transaction('category')
.objectStore('category').getAll();
}).then(function(allObjs){ return allObjs});
return val;
}
return factory;
});
Controller :
app.controller('catalogController', function($scope, database){
var cat = database.allCategories().then(function(allobjs){return allobjs});
console.log(cat);
});
I have tried everything but it still returns the promise not the result of the store which is actually an array. I have searched a lot but I was not able to find any answer which meets this.. Thanks.