Bootstrap Ionic 2 after platform ready


#1

My ionic2 app loads the main page and starts fetching the data using a custom DBService which in turn uses Cordova SQLite plugin, but at this time the platform is not ready and thus sqlitePlugin is not available.

Can anybody suggest what is the best way to delay bootstrap until the platform is ready (and SQlite db is open)?


#2

I was just experimenting with such an approach. This main.ts seems to work:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';

function bootstrap() {
  platformBrowserDynamic().bootstrapModule(AppModule);
}

if (window['cordova']) {
  document.addEventListener('deviceready', () => bootstrap());
} else {
  bootstrap();
}

Note that I’m using @ionic/app-scripts version 0.0.47 that requires a single main.ts file.


#3

Raised here: https://github.com/driftyco/ionic2-app-base/issues/114