I currently have a cordova app that uses a custom framework (which I don’t really like) and would love to switch to angularjs/ionic.
Currently, the app does something like:
$(document).ready(function () {
if (window.cordova) {
document.addEventListener('deviceready', __initialize, false);
} else {
__initialize();
}
});
This ensures that the document and the device (if running on a device) is ready before any other code is executed.
I know ionic has the $ionicPlatform.ready function, but to me code that requires the device to be ready may be executed before the device is ready by using this.
For instance, if we take a look at the demo weather app, notice that the WeatherCtrl uses $ionicPlatform.ready to hide the status bar. Also notice that the WeatherCtrl depends on the Geo and Weather services. What would happen if the Geo or Weather services required cordova features (and therefore the device to be ready) before they could function? Wouldn’t this create a race condition?
Wouldn’t it be better if we manually bootstrapped angular so that nothing is executed until the device is ready?
angular.element(document).ready(function() {
if (window.cordova) {
document.addEventListener('deviceready', function() {
angular.bootstrap(document.body, ['app']);
}, false);
} else {
angular.bootstrap(document.body, ['app']);
}
});