Wait $ionicPlatform.ready response before init controller


#1

Hello people,
Sorry for by bad english, i’m a french developer :slight_smile: (www.tibz.net)
i’m currently making an IOS mobile application with Ionic and i’ve got a little problem with first initialization.
I work with the sidemenu template from the beginning, my first controller is init from the

$urlRouterProvider.otherwise('/app/mycontroller'); 

In my first controller (my main rub), i need use $cordovaNetwork and other cordova plugin (ng-cordova is great guy!), to do this, i must wait a $ionicPlatform.ready response.
I already listen this event on app.js in the run method.

angular.module('vttapp', ['ionic','ngCordova','vttapp.controllers', 'vttapp.services','vttapp.utils'])
.run(function($ionicPlatform) {

 $ionicPlatform.ready(function(){
 // todo
 });

}).config..........

I want wait this event and only after initialise my first controller, i wan’t use the

$urlRouterProvider.otherwise('/app/mycontroller')

who initialise my controller before event is dispatched.
It’s possible it’s a tips about Angular (i’m newbie with), Thanks for your answers anyway!

I could wait a $ionicPlatform.ready directly from my first controller, but i want really do intialisation outside of my controller ($ionicPlatform.ready dispatch only one time)

Thanks !


#2

Hi! Sorry for my english, i’m russian developer =)
Did you solve this problem? I have the same problem, can you say your solution?


#3

I also met this problem recently.
One way is to subscribe the deviceready event and manually bootstrap the app.

But in my app I need to make sure the sqlite plugin is initialized and the database is opened successfully.
My current solution is first navigate to a loading page, when all the initialization logic is done in the $ionicPlatform.ready method, navigate to the first functional page.


#4

@twinssbc, Probably, you’d never expect that after two years, your reply still could save someone else’s day.
You saved my day. thank you!
I don’t use sqllite but I need to achieve something similar. ui-router for angular 1.x isn’t so straingforward in terms of handling async authentication. using a loading page allows me to get data ready before transiting to a route which requires authentication. I’d tried so many methods before I read your reply. None worked as what I expected. You solution isn’t an elegant one but the most important thing is , it works in my case.