Ionic Platform Ready as a promise


In one of my code I need to chain promises and wanted to know if this could be done with $ionicPlatform Ready :

return $ionicPlatform.ready()
    .then(function () {
       return $ngCordovaFunction();
    .then(function (result) {
        return doAction(result);

Where ngCordova is a promise from NgCordova lib and doAction() a promise which needs ngCordovaFunction() completion.

Because I use ngCordova, I have to use $ionicPlatform.ready() or document ready.

The problem is that without a promise it leads to weird issues.

I only wanted to know if the code above will be resolved or rejected any times and not running infinite sometimes.


1 Like

I would make your call within the ready callback like this:

$ionicPlatform.ready(function () {
      $ngCordovaFunction().then(function (result) {
              return doAction(result);

I was using it since I run into issues.

The issue with this code is that you can’t use it “as if” in other part of your project because it’s not a promise.

There is only one way to use it as a promise and it’s with defer, but sometimes and depending my functions I prefer to avoir defer :

On ionic website :

Returns: promise A promise which is resolved when the device is ready.

So if we took my above example, I understand that it will always be resolved or rejected. And when the device is ready it will enter in my then and do the ngFunction which is what I want.
If it’s the case it’s just perfect and elegant :smile: