In my Angular/Ionic App, I am trying to redirect an user to the state Setup
when he opens the app for the first time, and has not setup his default account settings yet. To do this,
Variables
if and only if the the user has setup his accountAuth
), see also belowsetupResolve()
tries to retrieve the data from the table Variables
, upon success it resolves the state 'Auth', upon failure it redirects the user to the state Setup
Here comes the issue:
$ionicPlatform.ready(){}
- see a tutorial here. So as you see you get in a Chicken or Egg situation. Concretely, in my code below, the function ionicPlatform.ready() is not firing when opening the app on my device.
The strange thing is that it works fine on Google Chrome, but my guess is that the ionicPlatform.ready() is bypassed in the browser, or that there are other criteria.
//
// I-1
self.openDb = function(method) {
//
var qOpen = $q.defer();
$ionicPlatform.ready(function() {
// ** NEVER REACHED WHEN USED IN RESOLVE CONTEXT **
// Open Db
if(window.cordova) {
db = $cordovaSQLite.openDB("starter.db");
} else {
db = window.openDatabase("starter.db", "1.0", "My app", 1024 * 1024 * 100);
}
// Create Tables
self.createTables().then(function(){
qOpen.resolve(true);
}, function(error){
qOpen.reject(error);
})
})
return qOpen.promise;
};
state auth, code in .config
Note: the setupResolve function calls the function openDb()
.state('auth', {
url: '/auth',
templateUrl: 'templates/single-auth.html',
controller: 'AuthCtrl',
resolve: {
setupResolve: setupResolve
}
})