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;

1 Answer 1

2

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

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

Link to Promise

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.