I'm trying to build a registration views, but my problem is that the checking statement if the user is already registered it performs in $ionicPlatform.ready
, like the following:
$ionicPlatform.ready(function() {
db = $cordovaSQLite.openDB({ name: "my.db" });
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS groups (id integer primary key, title text)");
if (typeof(Storage) != "undefined") {
// Store
var registered = localStorage["isRegistered"];
if(registered == undefined || !registered){
$location.path('/register');
}else{
$location.path('/tab/groups');
}
}
});
The problem that the $urlRouterProvider.otherwise('/tab/groups')
preforms before the ionic ready, it means that in the first opening of the application, it appears the groups tab then going to the registration view.
I tried to put the statement check if the user is already registered in the otherwise like the following:
$urlRouterProvider.otherwise(function($injector, $location){
if (typeof(Storage) != "undefined") {
// Store
var registered = localStorage["isRegistered"];
if(registered == undefined || !registered){
$location.path('/register');
}else{
$location.path('/tab/groups');
}
} });
Also, I face another problem that we arrive to the groups tab (getting groups from database) before we open the database in the ionic ready. Is there any solution to do the registration?
Ionic platform can be used anywhere in the code. You should be able to use
$urlRouterProvider.otherwise(function($injector, $location){
$ionicPlatform.ready(function(){
if (typeof(Storage) != "undefined") {
// Store
var registered = localStorage["isRegistered"];
if(registered == undefined || !registered){
$location.path('/register');
}else{
$location.path('/tab/groups');
}
}
});
});
Also, a state provider may be a better solution