1

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 = [];

$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;
Ahmad Abbasi
  • 1,776
  • 6
  • 29
  • 43

1 Answers1

2

Have a look at this answer. It makes use of Promise object.

https://stackoverflow.com/a/31869081/5336859

Link to Promise

Community
  • 1
  • 1
Abrar Ali
  • 115
  • 2
  • 14