$ionicPlatform.ready() Where can i read about on doc?

Ionic framework forum === The most active framework.!!

Where can i read about $ionicPlatform.ready() in doc or somewhere else?

1 Like

There isnā€™t a whole lot to it. If you go in the Ionic source could, you can see that it is just listening for the Cordova/phonegap deviceready event to fire.

  function onCordovaReady() {
    // the device is all set to go, init our own stuff then fire off our event
    ionic.Platform.isReady = true;
    ionic.Platform.detect();
    ionic.trigger('platformready', { target: document });
    document.removeEventListener("deviceready", onCordovaReady, false);
  }

This is in /ionic/js/utils/platform.js

2 Likes

Thankā€™s Calendeeā€¦ I understandā€¦

I just put together a platform docs page here: http://ionicframework.com/docs/angularjs/utils/platform/

2 Likes

I try to do a mix of your link and:

So i try:

angular.module('starter.controllers', ['ionic'])
.run(function(ionic) {
  ionic.Platform.ready(function(){
            console.log('platform ready');
  })

But I have:
Uncaught Error: [$injector:modulerr]

Whatā€™s the best practise to call ionic.Platform.ready

Not sure about ā€œbest practiceā€, but I use an overall ā€œappā€ controller and put it there:

angular.module('app.controllers').controller('AppController', [ '$scope', '$ionicPlatform', function($scope, $ionicPlatform){

    // Identify the country code for this device
    $ionicPlatform.ready(function() {

	    console.log('platform Ready!');
	};

});

Not sure either for ā€œbest practiceā€ but we use a factory (in a configuration Module with other constants defined)

.factory(ā€˜configFactoryā€™, [ā€™$ionicPlatformā€™,
function($ionicPlatform) {

          $ionicPlatform.ready(function() {

          });
          return $ionicPlatform.ready;

}])

Funny that itā€™s called docs/angularjs/page but on that specific page you made @adam not a single word is spoken about the AngularJS service implementation, only the core Ionic javascript code :smile:

Of course any well-thinking human being is able to derive some information from that docs page, but the URL is kind of misleading; I was expecting AngularJS information there :wink:

I am using $ionicPlatform.ready() in my main controller and I am seeing inconsistent behavior, sometimes the app loads and other times it doesnt. It is as if the ready callback is not always called.

This is on IOS

Will be cleared up very soon with the new generated documentation.

not really sure what this response means? I read through the latest release notes and there was nothing specific that spoke to the issue I am seeing.

What I meant is we are working on source-generated documentation and are hoping to release it within the next few days. It will make everything much clearer.

1 Like

Is there any difference between

ionic.Platform.ready(function(){
    console.log('ionic platform ready');
});

and

$ionicPlatform.ready(function() {
    console.log('$ionicPlatform ready');
});
1 Like

can I call function of first controller function from .run( onready function)

dont inject ionic in .run function