I am trying to return the array I got from the database using websql but its empty.
angular.module('starter.services', [])
.factory('Products', function() {
var db = openDatabase('db', '1.0', 'DB',5 * 1024 * 1024);
return {
all: function(subId) {
var products = [];
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM products where category_id ='+subId, [], function (tx, results) {
var len = results.rows.length, i;
for (i = 0; i < len; i++){
products.push(results.rows.item(i));
console.log(products);// this will print out the products
}
}, null);
});
console.log(products);// empty
return products;
},