I have a angularJS factory created to insert and get some values from IndexedDB. I can successfully insert the values to the IndexedDB. But when i try to get the values out of the DB and pass it to the controller i face problems.
factory.getAllProgressData = function() {
var dbOptions = {};
dbOptions.include_docs = true;
var output = {};
var result = {};
pouchDb.allDocs(dbOptions, function(err, res) {
if (err)
console.log(err);
if(res) {
output.weight = getWeightValues(res.rows);
console.log(output); // <== This console line prints the object
}
});
console.log(output); // <== This console line does NOT print the object
return output;
};
var getWeightValues = function(rows) {
var weightValues = [];
for (var i = 0; i < rows.length; i++) {
weightValues.push(rows[i].doc.Weight);
};
return weightValues;
};
As you can see in the comments of the code, when i print the object to the console at the first place it prints. But when i try to do it bellow it doesn't print. And the return value is also empty. I'm very new to javascript and this behavior is not clear to me. I want the result object to be returned to the Controller
. Please help. Thanks in advance.