Device Ready

how to check device ready. and if device not ready wait for device ready.

i did it this way:

<script type="text/javascript">
  document.addEventListener('deviceready', function onDeviceReady() {
    angular.bootstrap(document, ['myApp']);
  }, false);
</script>

so when the app starts all plugins are fully loaded.

We can write local database query inside onDeviceReady. is Correct?

$ionicPlatform.ready() look at the source code

yes this should be possible!

It will not working .Can u send sample for that.

Yes, confirmed. $ionicPlatform.ready() is not ready on device is ready. it’s probably called earlier. Simple check:

var app = angular.module('myApp', ['ionic',])
  .run(function($rootScope, $ionicPlatform) {
    $ionicPlatform.ready(function() {
      if (window.cordova) {
        $rootScope.sysVersion = $ionicPlatform.version();
      } else {
        $rootScope.sysVersion = 'unassigned';
      }
   })

Then try to output the sysVersion somewhere and it returns ‘unassigned’.

but if you try the cordova’s way:

var app = angular.module('myApp', ['ionic',])
  .run(function($rootScope, $ionicPlatform) {
    $ionicPlatform.ready(function() {
      if (window.cordova) {
        document.addEventListener("deviceready", app.onMyDeviceReady, false);
      } else {
        $rootScope.sysVersion = 'unassigned';
      }
    })

    app.onMyDeviceReady = function () {
       $rootScope.sysVersion  = device.version;
    }
	
   })

The sysVersion outputs correct system version. This is tested on three different Androids. I don’t know how this works on iOS.

Cheers,
Rafal

Can i use inside controller? if possible how?