我意识到$ionicPlatform.ready
函数默认在离子生成的app.js
文件中执行(在module.run下)
我的问题是:
是否仍然需要在使用需要$ionicPlatform.ready
的cordova插件的控制器中明确启动ondeviceready
?
答案 0 :(得分:0)
是否仍然需要明确启动$ ionicPlatform.ready 使用cordova插件的控制器,需要ondesviceready
如您所知app.js
a.e.在您的应用的生命周期中,run
方法被称为第一个。
但是,您也可以在多个控制器中实现$ionicPlatform.ready
。
ondeviceready
事件具有相同的行为,Ionic使用它并为您提供API $ionicPlatform.ready
。使用它是一个很好的做法,因为离子后得到回调
document.addEventListener("deviceready", onPlatformReady, false);
做了我们使用的其他好东西,如工具栏样式,键盘,其他离子插件等等
参考:
/**
* @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);
}
},
答案 1 :(得分:0)
您可以在启动/启动屏幕上进行检查,而不是继续使用应用程序的其余部分(使用控制器查看),直到设备准备就绪。然后,一旦您超过第一次检查,您就不需要在之后调用的各种控制器或服务中明确检查。