Hi all,
I just learnt to use resolve in $stateProvider for nest state. My goal is to initialize database before the app loads the very first view because I have to get data from database to show in the slidebox.
I tried to put DB.init() in $ionicPlatform.ready(function() {}). But it just works to ionic serve. When I run on my android phone, it can not open database before load the homepage.
Then i found resolve method. I tried it like this:
the abstract state for slidemenu
.state('app', {
abstract: true,
url:"/app",
templateUrl: "app/layout/menu-layout.html",
resolve: {
dbReady: function(DB){
console.log("dbReady");
return DB.init().then(function(){
console.log("db is Ready");
});
}
}
})
state define for home page
.state('app.home', {
url: "/home",
views: {
'mainContent': {
templateUrl: "app/home/home.html",
controller: 'HomeCtrl'
}
}
})
.state('app.games',
.state('app.game-detail',
.state('app.scanner',
.state('app.setting'
It actually works for both browser and Android. But it also bring a lot of error codes like:
D/CordovaLog(14201): Watchers fired in the last 5 iterations: []
D/CordovaLog(14201): http://errors.angularjs.org/1.3.6/$rootScope/infdig?p0=10&p1=[]
D/CordovaLog(14201): file:///android_asset/www/js/app.js: Line 54 : dbReady
D/CordovaLog(14201): file:///android_asset/www/js/services.js: Line 11 : initing db
D/CordovaLog(14201): file:///android_asset/www/js/app.js: Line 54 : dbReady
D/CordovaLog(14201): file:///android_asset/www/js/services.js: Line 11 : initing db
D/CordovaLog(14201): file:///android_asset/www/js/app.js: Line 54 : dbReady
D/CordovaLog(14201): file:///android_asset/www/js/services.js: Line 11 : initing db
D/CordovaLog(14201): file:///android_asset/www/js/app.js: Line 54 : dbReady
D/CordovaLog(14201): file:///android_asset/www/js/services.js: Line 11 : initing db
D/CordovaLog(14201): file:///android_asset/www/js/app.js: Line 54 : dbReady
D/CordovaLog(14201): file:///android_asset/www/js/services.js: Line 11 : initing db
D/CordovaLog(14201): file:///android_asset/www/lib/ionic/js/ionic.bundle.js: Line 19387 : Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
“dbReady” and “initing db” is console.log for me to know where the app runs to.
I can get what I want in the app test but I am worry about the errors…
Appreciate for the help…