Problem with global variable for db sqlite

Hello everybody, like the header, i have some issue with sqlite cordova. I declare a global variable

var db = null in app.js file

and create a factory AppDB in services.js like this:

.factory(‘AppDB’, function($cordovaSQLite, $localStorage){
var table = “statement create table”;
return {
db = $cordovaSQLite.openDB(“test.db”);
$cordovaSQLite.execute(db, table);
// execute query statement

in initDB function, i open db successfully, but when i try to call queryDB, the db is null. I don’t understand why it happen.
Please help me. Thanks u.

Look at this post. It is thoroughly discussed there.


Thank for your help. I get the answer from the blog The answer is so easy.