Device Ready


#1

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


#2

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.


#3

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


#4

$ionicPlatform.ready() look at the source code


#5

yes this should be possible!


#6

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


#7

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


#8

Can i use inside controller? if possible how?