Should we still include $ionicPlatform.ready in controllers that utilize cordova plugins requiring ondeviceready?
It is common knowledge that the app.js
file's run
method is the first to be called in the app's lifecycle.
Despite this, it is possible to implement $ionicPlatform.ready
in multiple controllers if needed.
The ondeviceready
event serves a similar purpose, with Ionic using it and providing the API $ionicPlatform.ready
. It is recommended to use this approach because Ionic performs additional tasks after receiving the callback from
document.addEventListener("deviceready", onPlatformReady, false);
, such as styling the toolbar, managing the keyboard, and interacting with other Ionic plugins.
For further information, please refer to:
/**
* @ngdoc method
* @name ionic.Platform#ready
* @description
* Trigger a callback once the device is ready, or immediately
* if the device is already ready. This method can be run from
* anywhere and does not need to be wrapped by any additonal methods.
* When the app is within a WebView (Cordova), it'll fire
* the callback once the device is ready. If the app is within
* a web browser, it'll fire the callback after `window.load`.
* Please remember that Cordova features (Camera, FileSystem, etc) still
* will not work in a web browser.
* @param {function} callback The function to call.
*/
ready: function(cb) {
// run through tasks to complete now that the device is ready
if (self.isReady) {
cb();
} else {
// the platform isn't ready yet, add it to this array
// which will be called once the platform is ready
readyCallbacks.push(cb);
}
},