mardi 20 octobre 2015

disable async db call in ionic

I am using this code to get data from database. but it always prints the result of this line console.log('outside ret data ' + retData); as undefined/null. because $cordovaSQLite.execute is an async call. How can i stop this until i get the result in the retData object. Please help

Code:

var retData = [];
console.log('dbReadyDeferred: ' + dbReadyDeferred);
console.log('function-getSupplierTypes called');
$cordovaSQLite.execute(db, "SELECT * FROM suppliertypes", []).then(function (res) {
     console.log("total rows found: " + res.rows.length);
     retData = res;

   }, function (err) {
            console.log("Error looking up Supplier types: " + err);
 });

        console.log('outside ret data ' + retData);
        return retData;

Aucun commentaire:

Enregistrer un commentaire