Hi,
I’m a bit confused about “when” things are executed in a ionic app.
I though app.run and ionicPlatform.ready would be the first things to run, but if I’m not wrong I think they’re not.
To test this, I have created a new app using ionic start, and added some console.log messages:
ionic start menuapp sidemenu
cd menuapp
ionic platform add android
# add console.log messages to app.js and controllers.js
cordova run android
And then I check the log:
adb logcat | grep CordovaLog
I/CordovaLog( 1339): Changing log level to DEBUG(3)
I/CordovaLog( 1339): Found start page location: index.html
I/CordovaLog( 1339): Changing log level to DEBUG(3)
I/CordovaLog( 1339): Found start page location: index.html
D/CordovaLog( 1339): file:///android_asset/www/js/app.js: Line 10 : app.run starting
D/CordovaLog( 1339): file:///android_asset/www/js/app.js: Line 25 : app.run done
D/CordovaLog( 1339): file:///android_asset/www/js/controllers.js: Line 4 : AppCtrl starting...
D/CordovaLog( 1339): file:///android_asset/www/js/controllers.js: Line 36 : AppCtrl done...
D/CordovaLog( 1339): file:///android_asset/www/js/controllers.js: Line 40 : PlaylistsCtrl starting...
D/CordovaLog( 1339): file:///android_asset/www/js/controllers.js: Line 49 : PlaylistsCtrl done...
D/CordovaLog( 1339): file:///android_asset/www/js/app.js: Line 12 : ionic.ready starting...
D/CordovaLog( 1339): file:///android_asset/www/js/app.js: Line 23 : ionic.ready finished
So, the controllers AppCtrl and PlaylistsCtrl are executed before ionic.ready has finished (or even started).
My question is… I need to initialize some services (ie, Analytics, ad serving…) before the controllers are executed. I thought $ionicPlatform.ready() was the place to do it, but am I wrong? Where should I do it?
Thanks for your help!
Iñaki