I am creating an app where I wish to redirect a user directly to home page if he is logged in. I am using cordovaSQLite plugin to check if he is logged in or not. But I am not getting the value of cart_status. Is it because I am executing the query in angular.module ? I see that I can execute CREATE TABLE query in angular.module which stands a valid reason I should be able to execute some other query as well.
Here is my code
var db = null;
var ab= ""
angular.module('starter', ['ionic', 'starter.controllers', 'ionic-material', 'ionMdInput', 'ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
.
.
.
db = $cordovaSQLite.openDB({ name: "userdb", location: 0});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS user_info (id integer primary key, firstname text, lastname text, user_id text, cart_id text, cart_status text, header_token text)");
var cart_query = "select cart_status from user_info LIMIT 1";
$cordovaSQLite.execute(db, cart_query, [])
.then(function(suc){
ab = suc.rows.item(0).cart_status
},
function(uerr){
alert(JSON.stringify(uerr))
})
});
})
And here
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
.
.
.
alert(ab) // which is blank
})