Ionic.Platform.ready is not ready


#1

I am trying to detect that Cordova is ready so that I can start putting my device specific code.
So i am using the following and it doesn’t seem to work:-

    ionic.Platform.ready(function(){  
    	     console.log("cordova:",ionic.Platform.isCordova()); 
    	     console.log("paltform:",ionic.Platform.platform()); 
    	     console.log("version:",ionic.Platform.version()); 
 	});

all values are undefined… of course i am running on the device. and it is running from the app.run function.

i suspected this could be a problem with cordova, not with ionic, so i tried to do it directly with Javascript and it worked fine:-
document.addEventListener(“deviceready”, onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the Cordova API
console.log(“Device is ready”);
var element = document.getElementById(‘deviceProperties’);

    element.innerHTML = 'Device Name: '     + device.name     + '<br />' + 
                        'Device Cordova: '  + device.cordova + '<br />' + 
                        'Device Platform: ' + device.platform + '<br />' + 
                        'Device UUID: '     + device.uuid     + '<br />' + 
                        'Device Model: '    + device.model     + '<br />' + 
                        'Device Version: '  + device.version  + '<br />';
	}

This sounds like a really basic functionality in ionic Framework, i am not sure why it doesn’t work?


Yeo ionic generator & cordova?
#2

Where exactly are you putting that code? What version of Ionic are you using?

Here is how the sample apps (from Getting Started) use it:

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers'])

.run(function($ionicPlatform, $timeout) {
  $ionicPlatform.ready(function() {
    
    console.log('Platform ready!');

    if(window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

It seems maybe you’re using an old version of just using it wrong with ionic.Platform.ready. It needs to be $ionicPlatform.ready in the newer releases.


#3

Calendee, thank you for the prompt response, I tested again this morning and my problem turned out to be completely different.
i am using the following to check the information:-

console.log("cordova:",ionic.Platform.isCordova());

and it looks like console.log does not work very well in Cordova, i have to put it like this:-

console.log("cordova:" + ionic.Platform.isCordova()); 

otherwise, the information after the comma in the first statement will appear as empty.

That was misleading to me, and to you , i am sorry about that.

I am using the latest version 1.0.0 beta of ionic, and both $ionicPlatform and ionic.Platform are working now perfectly.
Note that if ionic.Platform should not be used in that case, it still appears in the documentation here:-
http://ionicframework.com/docs/api/utility/ionic.Platform/

Best Regards,
Michel.